I have a WordPress page named Services where the content is custom HTML (added in the Text tab in TinyMCE). I'm trying to use WP_Query on the splash page to pull the Services content and display it inside a DIV. What I'm getting however is plain text. It looks like WP_Query is parsing the HTML and then displaying what is left. The URL is not public, but here is my PHP recommended by the theme tech support (ElegantThemes/Vertex) ...

<section class="home-block et-odd">
<div class="container">

<?php $the_query = new WP_Query( 'page_id=4' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post();  ?>
<?php the_excerpt(); ?>
<?php endwhile;?>

</div> <!-- .container -->
  • 1
    Did you try the_content() instead of the_excerpt() ?
    – birgire
    Jul 5, 2018 at 21:45
  • First, the_content() worked beautifully. The tut I was looking at only talked about how to use the_excerpt() and not the other options. I also found info explaining that WP_Query is an 'object' etc. Thanks!
    – Luke 5 Dev
    Jul 6, 2018 at 13:55

1 Answer 1


WP_Query object contains FULL content of posts/pages retrieved from database. No HTML tags are being removed. Therefore, the following statement in your question:

It looks like WP_Query is parsing the HTML and then displaying what is left.

is not true.

If you use, in your code, the_content() instead of the_excerpt() function, you'll see that all original HTML tags are preserved.

It is important to understand how excerpts are being generated. What is being displayed by the_excerpt() function? This is the code:

echo apply_filters( 'the_excerpt', get_the_excerpt() );

get_the_excerpt() function is responsible for generation of the excerpt's text.

From Codex:

Returns the excerpt of the post. This is either a user-supplied excerpt, that is returned unchanged, or an automatically generated word-counted trimmed-down version of the full post content.

The auto-generated excerpts have all shortcodes and tags removed which means it is just an unformatted string that would not see any line-breaks in any form of output, since the actual line-breaks in the raw text are also removed.

In your case, the_excerpt() function displays an auto-generated excerpt, with HTML tags removed. To change this behavior, you can use 'the_excerpt' filter to add HTML formatting, or fill page's Excerpt meta-box, with desired, HTML formatted text.

  • Frank your comments along with previous tip exactly what I needed. Thank you very much!
    – Luke 5 Dev
    Jul 6, 2018 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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