Last active
January 23, 2017 02:57
-
-
Save gschoppe/cca2636cf7447e3dfe0d836d41d2fa0c to your computer and use it in GitHub Desktop.
Hide shortcodes if rendering fails in WordPress 4.7+
This file contains 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
<?php | |
/* | |
* Hide shortcodes in excerpts or if rendering fails | |
* Usage: <!--[shortcode-name comment-wrapped=true]--> | |
*/ | |
add_filter( 'do_shortcode_tag', "comment_wrap_shortcodes", 10, 3 ); | |
function comment_wrap_shortcodes( $output, $tag, $atts ) { | |
$args = shortcode_atts( array( | |
'comment-wrapped' => 'false' | |
), $atts ); | |
$wrapped = strtolower( $atts['comment-wrapped'] ); | |
if( !( $wrapped === 'false' || $wrapped === '0' || empty( $wrapped ) ) ) { | |
$output = "-->" . $output . "<!--"; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment