Removing Undesired Paragraphs Around Page Content in WordPress

Sometimes the way WordPress deals with paragraphs when displaying the page content manages to become annoying.

For instance, I was trying to vertically align the image with the text in the page presented below. The image is the featured image for the page and the text is the page content.

Screen Shot 2015-06-12 at 10.39.19 AMParagraphs have vertical margins and they cannot be removed because we won’t be able to tell where they are anymore.

After some research, I found the culprit: the the_content() function. It reformats the content by using paragraphs.

The solution is simple:

In your page.php and other page templates replace the code <?php the_content(); ?> with

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

That’s it. Enjoy WP 🙂