How can I output ONLY the post content (ie the text entered into the wysiwyg) and nothing else? i just need this for the posts in a specific category, so if i could call like say,

<?php get_template_part( 'venue_content', 'single' ); ?>

it would be ideal.

  • you should mark chip's answer as accepted -- that way people will know you're not still looking for one when they scan the list of questions. – marfarma Aug 28 '12 at 20:00

Assuming you are in the loop, or otherwise know (or know how to get) the $post object:

function wpse63358_get_post_content() {
    global $post;
    return $post->post_content;

If you want the formatted post content, replace this:

return $post->post_content;

...with this:

return apply_filters( 'the_content', $post->post_content );

To echo the function output:

echo wpse63358_get_post_content();


Note: if you just want to output post content in the template, you don't actually even have to bother with wrapping it in a function. Simply use:

global $post;
echo apply_filters( 'the_content', $post->post_content );
  • Or the single template for the OP's 'venue_content' could simply contain the line echo apply_filters( 'the_content', $post->post_content ); – marfarma Aug 28 '12 at 17:03
  • @marfarma yes, of course; but I based my answer on the wording of the title: "how can i write a function that returns ONLY the post body". :) – Chip Bennett Aug 28 '12 at 18:47
  • chip - I tried yours and couldn't figure out how to get it to work; not your fault, mine, for not being so familiar with altering default wordpress functionality. :) – jamie Aug 28 '12 at 19:50
  • @jamie: you would define that function in functions.php, and then call it wherever you want the post content to output - i.e. wherever you currently have echo apply_filters( 'the_content', $post->post_content );. But that said, it would probably be more accurate to update the wording of the question/title. – Chip Bennett Aug 28 '12 at 20:03

I think you can also use 'Post formats' for this, either the aside or the quote format I believe displays just the main content - http://codex.wordpress.org/Post_Formats

  • cool, that is new to me, i'll definitely check it out! – jamie Sep 6 '12 at 17:20

If you want to output only the post content, excluding any shortcodes, try something like this.

global $post;
$postContentStr = apply_filters('the_content', strip_shortcodes($post->post_content));
echo $postContentStr;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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