How to appending to the_content using add_filter with custom post type?

Written by  on November 23, 2016 

I have a custom post type running fine, but some of the text in the page is the same for every post, so I want to add it in using a function.

I have this set up:

function new_default_content($content) {
global $post;
    if ($post->post_type == 'custom-post-type') {
    $content = 'Test text here';
    return $content;
add_filter('the_content', 'new_default_content');

However when I refresh the page, I only see “Text test here” and not the the post’s content (from the_content).

If I comment out this function, the post content reappears. What am I doing wrong?

Category : Wordpress

Tags :