mihdan
9/28/2016 - 4:02 PM

Strip out all Shortcodes for a WordPress AMP template.

Strip out all Shortcodes for a WordPress AMP template.

<?php
/**
 * Strip out all shortcode content.
 * 
 * This is a quick and dirty way
 * to ensure no shortcodes introduce
 * invalid markup into an amp template.
 * 
 * @param string $content WP Post content.
 * 
 * @return string
 */
function jr3_amp_strip_all_shortcodes( $content ) {
	global $shortcode_tags;
	if ( ! is_amp_endpoint() || empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
		return $content;
	}
	
	$regex = get_shortcode_regex();
	preg_replace( "/$regex/", '', $content );
	
	return $content;
}
add_filter( 'the_content', 'jr3_amp_strip_all_shortcodes' );