Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mihdan/2473b14b9d78660b4b1de4fbeb42ce62 to your computer and use it in GitHub Desktop.

Select an option

Save mihdan/2473b14b9d78660b4b1de4fbeb42ce62 to your computer and use it in GitHub Desktop.
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment