gschoppe
1/23/2017 - 2:32 AM

Hide shortcodes if rendering fails in WordPress 4.7+

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;
}