文章前后添加固定内容

在所有Wordpress文章(文章,项目,产品等一切post)前后添加自定义内容,可用简码来插入即可控制好内容。

[php]
function my_content_filter($content){
//only add text before WordPress posts
if(is_single() && is_main_query()){
$before = '<p>This content will go before WordPress posts</p>';
$after = '<p>This content will go after WordPress posts</p>';
//或者用简码 $after = do_shortcode('简码');

//modify the incoming content
$content = $before . $content . $after;
}
return $content;
}

add_filter( 'the_content', 'my_content_filter' );
[/php]

如何判断什么文章类型?指定Post type才显示

[php]
// Run code only for Single post page
if ( is_single() && 'post' == get_post_type() ) {

}

//if it's not a specific post-type
if ( is_single() && 'portfolio' != get_post_type() ) {

}

[/php]

需要外贸独立站建站或 GEO 优化服务?美络云科技(Mloun)提供 WordPress 外贸独立站建站、WooCommerce 跨境商城、海外 SEO 与 GEO 生成式引擎优化一站式服务,服务覆盖全球 25% 的国家和地区。