替换在content-single.php中使用functions.php中自定义内容代码的输出

替换在content-single.php中使用functions.php中自定义内容代码的输出,php,wordpress,Php,Wordpress,我有个小问题。在某人的帮助下,我成功地编写了一个代码,将动态内容添加到我所有的wordpress帖子中。代码现在位于my functions.php文件中,如下所示 function add_after_post_content($content) { global $post; if(!is_feed() && !is_home() && is_singular() && is_main_query()) { $p

我有个小问题。在某人的帮助下,我成功地编写了一个代码,将动态内容添加到我所有的wordpress帖子中。代码现在位于my functions.php文件中,如下所示

function add_after_post_content($content) {
    global $post;
    if(!is_feed() && !is_home() && is_singular() && is_main_query()) {
        $post_categories = wp_get_post_categories( $post->ID );
        $cats = array();

        foreach($post_categories as $c){
            $cat = get_category( $c );
            $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
        }

        $content .= '<strong>'. $post->post_title . '</strong> is a <strong>wallpaper</strong> posted in the ';

        foreach($cats as $c){
            $content .= $c['name'];
        }

        $content .= ' category by <strong>Free Wallpapers</strong> on '. $post->post_date . '. <br /><br />';
    }
    return $content;
}

add_filter('the_content', 'add_after_post_content');
问题是,我的一些旧帖子中已经有内容,因此旧内容和新内容都显示在它们下面。鉴于我希望这是所有帖子的新内容/描述。目前在我的content-single.php中,我相信这是一行调用原始帖子内容加上我上面提到的代码

<?php the_content(); ?> 
我想删除或修改添加到functions.php文件中的content-single.php/code,以便只有新代码显示动态描述,而不显示原始帖子内容。i、 简单地说,如果整个新代码可以标记为content2,content-single.php代码将只输出这个content2。我尝试过简单地将代码从functions.php移到replace

<?php the_content(); ?> 
在content-single.php中,但这会给我带来各种各样的错误

在此问题上的任何帮助都将不胜感激


致意

删除$content后面的圆点

$content .= '<strong>'. $post->post_title . '</strong> is a <strong>wallpaper</strong> posted in the ';
将上述行替换为以下内容

$content = '<strong>'. $post->post_title . '</strong> is a <strong>wallpaper</strong> posted in the ';