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

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' );

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

// 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() ) {

}