Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove empty <p> tags from wordpress shortcodes via a php functon

Looking for a php function (non-jQuery or wpautop modification) approach to remove <p></p> from within wordpress.

I tried this but it does not work:

        function cleanup_shortcode_fix($content) {   
          $array = array (
            '<p>[' => '[', 
            ']</p>' => ']', 
            ']<br />' => ']',
            ']<br>' => ']'
          );
          $content = strtr($content, $array);
            return $content;
        }
        add_filter('the_content', 'cleanup_shortcode_fix');
like image 308
Jason Avatar asked Nov 22 '12 10:11

Jason


People also ask

How do I remove a shortcode from a Wordpress page?

One way to remove the shortcodes is by going through each post and page and editing them. Another way we can create shortcodes again and make sure it outputs nothing. This way you can just add a small function in your functions. php file and the shortcode will go away from all your post and pages.


1 Answers

Try inserting this code in your functions.php file:

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 99 );
add_filter( 'the_content', 'shortcode_unautop', 100 );

enter image description here

like image 171
m1r0 Avatar answered Oct 21 '22 13:10

m1r0