-
-
Save bhongy/6761732 to your computer and use it in GitHub Desktop.
<?php if ( get_the_content() ) { ?> | |
// do or output something | |
<?php } ?> // break php tag for HTML block |
the_content()
also applies the the_content
filter to the result of get_the_content()
, so the method above might not actually work :/
`
just to summarize:
$the_content = apply_filters('the_content', get_the_content());
if ( !empty($the_content) ) {
echo $the_content;
}
the_content()
also applies thethe_content
filter to the result ofget_the_content()
, so the method above might not actually work :/
Is there a use-case where this should be a problem for an empty check? Just wondering if I still use the_content()
for displaying the content and empty check using get_the_content()
, shouldn't be an issue right.
No need to use empty(), this works fine:
if ( get_the_content() ) {
// do whatever!
}
If your post is empty, get_the_content
will return an empty string, and in an IF statement PHP will interpret an empty string as FALSE.
That worked for me @drdogbot7 !
Thanks
Thanks, @drdogbot7! Updated the gist per your suggestion.
if ( get_the_content() ) { // do whatever! }
thanks you for question
You could perfectly replace
by
And Thank you for the snippet :)