Last active
October 20, 2021 17:43
-
-
Save johnregan3/e18ae44e9139d0de7426681d3caed785 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 ( ! amp_is_request() || empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { | |
return $content; | |
} | |
$regex = get_shortcode_regex(); | |
$content = 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
Updated. Thanks @DevWael !