是否可以在自定义的WordPress标题上添加前缀,使其出现在RSS提要和其他共享媒体上?
例如:
自定义帖子类型 = 产品标题 = 一个新的茶杯
产量 = 产品 - 新茶杯
尝试过滤the_title_rss
,并在自定义帖子类型前面加上前缀(如果它不是post
):
function rss_cpt_title($title) {
global $post;
$post_type = get_post_type($post->ID);
if ($post_type != 'post'){
$title = $post_type . ' - ' . $title;
}
return $title;
}
add_filter('the_title_rss', 'rss_cpt_title');
您可能需要摆弄条件,因为get_post_type可能会返回一个 slug,并且它可能区分大小写。