Skip to content

Instantly share code, notes, and snippets.

@palmiak
Created February 1, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palmiak/6056b4d5dbc66452e75a4218edc4d5c5 to your computer and use it in GitHub Desktop.
Save palmiak/6056b4d5dbc66452e75a4218edc4d5c5 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'the_content', 'strip_usless_shortcodes', 50 );
function strip_usless_shortcodes( $content ) {
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
$pattern = get_shortcode_regex( $matches[1] );
$content = preg_replace_callback( "/$pattern/", 'strip_usless_shortcodes_callback', $content );
$content = str_replace( '<p></p>', '', $content );
return $content;
}
function strip_usless_shortcodes_callback( $matches ) {
return $matches[5];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment