开发者

How to hide certain tags from the_tags() in WordPress?

I need to assign some tags to my posts (for external use), but I don't want them showing anywhere t开发者_C百科hat tags are listed. Can someone please give me an example as to how to do this?


this question is very old but i came across this need and i found an interesting solution that i wanted to share.

It is better to apply a filter to the tags and you won't be afraid of missing points in your template where you show tags.

function exclude_tags($tags) {
 foreach ($tags as $tag)
  switch ($tag->name) {
   case 'exclude-this-tag':
   case 'exclude-this-tag-too':
    break;
   default:
    $newtags[] = $tag;
 }
 return $newtags;
}
add_filter( 'get_the_tags', 'exclude_tags');


Use get_tags() instead of the_tags() in your templates

 $tags = get_tags();

 foreach ($tags as $tag)
 {
   if($tag->name=='the tag i want gone') continue;// do this for every tag you want gone
   echo $tag->name.', ';  
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜