您要编辑title, 而不是content.
检查此filters 您要使用。
如果要编辑title 你应该add_filter 并对其进行修改(the_title). 像这样:
add_filter(\'the_title\', \'addBadge2Title\');
function addBadge2Title($title)
{
$seconds = strtotime("now") - strtotime(get_the_date("Y/m/d"));
$badge = get_stylesheet_directory_uri() . \'/library/images/new_ribbon.gif\';
if ($seconds < 10950400) {
$title = \'<img class="new_ribbon" width="75" height="75" src="\' . $badge . \'" >\' . $title;
}
return $title;
}
编辑:仅对特定类别使用徽章如果要对特定类别使用此代码,您有几个选项
第一次删除add_filter(\'the_title\', \'addBadge2Title\'); 只保留function 在中声明functiosn.php 在archive-{$category-slug}.php 文件按如下方式添加和删除筛选器
if(have_posts()) : while(have_posts()) : the_post()
add_filter(\'the_title\', \'addBadge2Title\');
the_title();
remove_filter(\'the_title\', \'addBadge2Title\');
endwhile; endif;
检查当前帖子是否包含您希望标题显示为徽章的类别。修改
function 通过添加
has_category 像这样:
function addBadge2Title($title)
{
// return the $title unmodified if the post does not have the category
if(!has_category(\'badge-category\'))
return $title;
// add the badge
$seconds = strtotime("now") - strtotime(get_the_date("Y/m/d"));
$badge = get_stylesheet_directory_uri() . \'/library/images/new_ribbon.gif\';
if ($seconds < 10950400) {
$title = \'<img class="new_ribbon" width="75" height="75" src="\' . $badge . \'" >\' . $title;
}
return $title;
}