Last active
September 27, 2021 13:31
-
-
Save gaelbillon/bf6d3754b31da58faa1f233df298297d to your computer and use it in GitHub Desktop.
Shortcode to display the post content if it is not empty, otherwise it displays a fallback text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shortcode : [post-content-with-fallback-text-if-empty] | |
function empty_content($str) { | |
return trim(str_replace(' ','',strip_tags($str))) == ''; | |
} | |
function my_sc_content() { | |
$post = get_post( $id ); | |
$content = $post->post_content; | |
if ( ! $post ) { | |
return ''; | |
} | |
if (empty_content($content)) { | |
return "La description de ce projet n'est pas encore renseignée."; | |
} else { | |
return $content; | |
} | |
} | |
add_shortcode('post-content-with-fallback-text-if-empty','my_sc_content'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment