Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You're completely overwriting the content instead of appending it. You need to do something like $content .= 'Test text here'; instead.

share|improve this answer
    
Much power in that period, thanks! Another question: I am using a plugin to display social buttons for Like, +1 etc and they are appearing above the new-default-content — is there a way to get the buttons to appear below? I assumed this filter would "chunk" the_content & new_default_content as one complete section. –  George C Sep 13 '11 at 15:45
1  
Well, you're appending the new content, so it's going to appear afterward. You might try hooking the filter in at a higher priority to get it to process before the plugin does, because the plugin is also using the same filter. –  helenhousandi Sep 13 '11 at 17:27
    
Ah, I will look into the priorities thing — thanks again! –  George C Sep 14 '11 at 5:46
    
FYI I played around with the priority and that did the trick! Thanks again :) –  George C Sep 14 '11 at 17:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.