I am using get_the_content()
to load other pages content on the current page, and I noticed some block CSS classes are missing in the HTML I get.
For example, is-layout-flex
layout CSS class is missing for the Columns block, which is causing block to look different from how it looks when the page is open normally, in a browser tab.
When I open page normally, in a browser tab I get this:
<div class="is-layout-flex wp-container-7 wp-block-columns">
But, when I get the content of the page with the get_the_content(), I get this:
<div class="wp-block-columns">
Is there a way to make get_the_content()
provide exactly the same content as it is provided when the page is open normally, in a browser tab?
the_content()
? Why mustget_the_content()
? Because it will return the raw block HTML with the block comment delimiters like<!-- wp:columns -->
.the_content()
as well.the_content()
, unless if you don't want the filters like mentioned here (and many other filters) to be applied, which also means you'd need to manually apply thedo_blocks()
to ensure blocks are parsed properly (e.g. specific CSS classes are added).get_the_content()
returns the content, whereasthe_content()
displays (i.e.echo
) the content. Butthe_content()
is not simply a shorthand/wrapper forecho get_the_content()
.