Javier Villanueva
Javier Villanueva

Reputation: 4058

Add paragraph tags to post content in wordpress?

I'm getting some pages with the get_pages function and echoing the page content like: $page->post_content, but contrary to the_content(), this way wordpress wont add p tags automatically, is there any way to add them here?

Thanks in advance

Upvotes: 7

Views: 16763

Answers (4)

CodyRob
CodyRob

Reputation: 249

This might be what you're looking for, isn't it?

<?php

// Get WordPress pages
$wp_pages = get_pages();

foreach ($wp_pages as $wp_page)
{
    echo '<p>';
    echo $wp_page->post_content;
    echo '</p>';
}

Upvotes: -4

Tom Auger
Tom Auger

Reputation: 20111

Jose Carlos' answer is actually the better approach. Out of the box, 'the_content' filter is loaded with the following actions:

  • capital_P_dangit
  • wptexturize
  • convert_smilies
  • convert_chars
  • wpautop
  • shortcode_unautop
  • prepend_attachment

So you can see that there's a lot more intelligence behind this filter. If you're positive that you don't need the other stuff (are you 100% sure you'll never have shortcode or smilies in your text?) then go ahead and use wpautop(), but you may regret it later on.

Upvotes: 3

Jos&#233; Carlos
Jos&#233; Carlos

Reputation: 1015

You should use <?php echo apply_filters('the_content', $page->post_content); ?>

Upvotes: 27

alex
alex

Reputation: 490403

Use the wpautop() function.

Upvotes: 17

Related Questions