我是wordpress插件开发的新手。我想自定义wordpress帖子标题而不是页面标题。我写了这段代码。
add_filter( 'the_title', 'change_title', 10, 1 );
function change_title( $title ) {
$title = 'Posted: ' . $title;
return $title;
}
它会更改(页面和帖子)标题。如何仅在帖子标题上应用此过滤器?
答案 0 :(得分:1)
add_filter('the_title', 'change_title', 10, 2);
function change_title($title, $id)
{
if (get_post_type($id) == "post") $title = 'Posted: ' . $title;
return $title;
}
享受