I was working on the new theme in the WordPress and spent tons of time with the get_the_content() function.
<div class="clearfix">
<div>
<p><?=get_the_content();?></p>
</div>
</div>
Seems that it doesn't process shortcuts and doesn't do paragraphs.
Then I replaced it with the the_content(); and my paragraphs and shortcuts started to work.
<div class="clearfix">
<div>
<p><?=the_content();?></p>
</div>
</div>
My question: What is the difference between the functions and what additional processing the_content(); does comparing to get_the_content();?
get_the_content()
does not pass the content throughthe_content
. Which means that it does not auto-embed videos, or expand shortcodes, among other things.Just use
get_the_content()
and it will remove those tags.https://codex.wordpress.org/Function_Reference/get_the_content https://developer.wordpress.org/reference/functions/the_content/
While @J Quest provided an adequate answer, I'd like to elaborate a little bit. Generally speaking, WordPress has two types of post variable functions:
get_
functions andthe_
functions.get_
functions, such asget_the_content()
orget_the_ID()
will return the desired information, which must then be manipulated and printed to the page. Some examples:the_
functions, such asthe_content()
andthe_ID()
actuallyecho
the returned value, and if applicable will apply the "default filters" for the appropriate values. These functions don't need to be echoed.is functionally the same as
If you look at the docs for
the_ID()
you'll see it literally just outputs the value ofget_the_ID()
. From the source:In that vein, if you try and set
the_
functions as a variable, you'll leave a trail of echoed variables throughout the page.will output:
To use
get_the_content()
and get shortcodes to run, you'll either need to run it through thedo_shortcode()
function, or better yetthe_content
filter.If you just need to spit out post content in a template, without any manipulation, you're typically better off with (no echo or echo short tag):