strip only specific tags (like ), but keep other tags (like )

You’d better never disable those actions (what you say). Instead, insert add_filter('the_content', 'MyFilter', 88 ); and create such function:

function MyFilter($content){
    $tags = array( 'p', 'span');
    ///////////////////////////////////////////////////
    ///////// HERE INSERT ANY OF BELOW CODE  //////////
    ///////////////////////////////////////////////////
    return $content;
}

======== METHOD 1 =========

$content= preg_replace( '#<(' . implode( '|', $tags) . ')(.*|)?>#si', '', $content);
$content= preg_replace( '#<\/(' . implode( '|', $tags) . ')>#si', '', $content);

======== METHOD 2 ======

foreach ($tags as $tag) {
    $content= preg_replace('#<\s*' . $tag . '[^>]*>.*?<\s*/\s*'. $tag . '>#msi', '', $content);
}

======== METHOD 3 =========

DOM object (preferred): https://stackoverflow.com/a/31380542/2377343

Leave a Comment