我需要为我的帖子分配一些标签(供外部使用),但我不希望它们显示列出标签的任何地方。有人可以举个例子来说明如何做到这一点吗?
答案 0 :(得分:2)
在模板中使用get_tags()代替the_tags()
$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.', ';
}
答案 1 :(得分:2)
这个问题很老,但我遇到了这个需求,我发现了一个有趣的解决方案,我想分享。
最好对代码应用过滤器,并且您不会害怕模板中显示标记的缺失点。
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');