WordPress.org

Support

Support » How-To and Troubleshooting » Remove the `<p> tag in template tag the_content?

Remove the `<p> tag in template tag the_content?

  • I’ve got two instances of The Loop on my front page. One howing the main feed and another one showing short post from another category.

    In the second instance of the loop I’m displaying the items in an unordered <li> list so I don’t want to use the <p>tag that comes included in the tags default output. Is there template tag option to exclude that p-tag or do I have to manually delete that from the code?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Instead of the_content() tag, try this:

    <?php echo $post->post_content; ?>

    This will display post content “raw”, in that it won’t make use of any of the auto-formatting functions. But if you need that, there’s a way around that as well.

    That method seemes to be working perfectly for my purposes. Thanks very much Kafkaesqui!

    Ah! Somebody else had this problem, too. Now for my question: how can this method be used with teaser text? That is, I want to use extended entries, but the fix given above sounds like it’s just going to print the whole entry all the time.

    Any thoughts on doing this while preserving the teaser text, folks? 🙂

    thanks, Kafkaesqui… that worked well… but now i’m curious, how do you get the filters to apply, but without wrapping the whole thing in a tag? or better yet, selectively apply the filters?

    Teasers, I think, are also known as asides, so you might find more information at http://codex.wordpress.org/Adding_Asides

    etoile: I think you can do the same thing with the_excerpt if you want to just have the first 120 characters (or whatever it is) of the post. Is that what you mean by a “teaser”?

    Instead of

    <?php echo $post->post_content; ?>

    I think it would be

    <?php echo $post->post_excerpt; ?>

    If that works, thank Kafkaesqui and this thread.

    http://wordpress.org/support/topic/39146#post-220911

    Just a note that a teaser in WordPress terminology is the text before the <!--more--> Quicktag. Thought it important to toss that out there.

    Using echo $post->post_excerpt works only if there’s an actual excerpt. It would display whatever is found in the post_excerpt column. Of course if that’s what’s being used for the “teaser,” it’ll work great.

    atdilts, you can apply filters individually by wrapping $post->post_content in the various filter functions, as shown here:

    http://wordpress.org/support/topic/35504#post-201193

    or you can hit them all at once (and thereby properly apply both internal and plugin filters on the content):

    <?php
    echo apply_filters('the_content', $post->post_content);
    ?>

    @kafkaesqui,
    doesn’t the code on the post above give the same output as <?php the_content(); ?>

    Not quite. For example, it ignores the <!--more--> Quicktag, as well as the post password, etc. It’s just a way of bypassing the functionality specifically inherent in the_content() while still picking up the formatting. That is, if you *really* need to. :)

    Hmm, I see. But wpautop is still applied, though, which is not desired in this case.

    alphaoide, hence the link:

    http://wordpress.org/support/topic/35504#post-201193

    Just remove wpautop() from the function nesting.

    I see and understand the wpautop() function above. This is a lot of a work-around for just getting rid of the tags on each blog post. Is there a way for this to become a setting at some point. Seems like it would really be 2 settings: Keep WYSIWYG line breaks? { y | n } and Wrap posts in tags? { y | n }

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Remove the `<p> tag in template tag the_content?’ is closed to new replies.
Skip to toolbar