Forked from johnregan3/wp-amp-tutorial-strip-shortcodes.php
Created
September 28, 2016 16:02
-
-
Save mihdan/2473b14b9d78660b4b1de4fbeb42ce62 to your computer and use it in GitHub Desktop.
Strip out all Shortcodes for a WordPress AMP template.
This file contains hidden or 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 | |
| /** | |
| * 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