Skip to content

Instantly share code, notes, and snippets.

@laxmariappan
Created February 15, 2019 06:38
Show Gist options
  • Save laxmariappan/b21cd088e01ad1ad95ae1a1d27c697e0 to your computer and use it in GitHub Desktop.
Save laxmariappan/b21cd088e01ad1ad95ae1a1d27c697e0 to your computer and use it in GitHub Desktop.
Wordpress: Check if the_content is empty / return custom text only when the_content is empty
// Check if the content is empty and show a custom message //
add_filter('the_content', 'text_for_empty_content', 20, 1);
function text_for_empty_content($content){
if(empty($content)) // Check if the content is empty
return '<p>Under Construction</p>'; // Add your custom text or other HTML
else
return $content; // if content is there, just leave it as it is
}
/*
Developer Notes:
When you do this check using get_the_content() - the_content() filter will not work.
As the content does not pass through the_content filter, action filters from other plugins / theme will not work.
To avoid this, use the above mentioned hook and customize it to your needs
Works in WordPress 5+, PHP 7
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment