Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Last active January 23, 2017 02:57
Show Gist options
  • Save gschoppe/cca2636cf7447e3dfe0d836d41d2fa0c to your computer and use it in GitHub Desktop.
Save gschoppe/cca2636cf7447e3dfe0d836d41d2fa0c to your computer and use it in GitHub Desktop.
Hide shortcodes if rendering fails in WordPress 4.7+
<?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