内页要显示的话就用楼上代码是最简单,那就改进下,需要用到下面的两段代码,添加位置就是上面说的:
把网站的名称改成简码调用的
// Get WordPress site name via shortcode: [yw_site_name]
function yw_site_name_shortcode() {
return get_bloginfo('name');
}
add_shortcode('yw_site_name','yw_site_name_shortcode');
改进后的代码如下:
add_filter( 'the_title', 'wpb_sponsored' );
function wpb_sponsored( $title ) {
global $post;
$sponsored_text = '<span class="sponsored_text"> [yw_site_name] </span> ';
$sponsored = get_post_meta($post->ID, 'sponsored', true);
if( $sponsored == 'true' && in_the_loop() ){
return $sponsored_text.$title;
}
return $title;
}