wordpress shortcode empty p tags issue

Updated on     Kisan Patel

Problem:

remove empty <p> tags from wordpress shortcodes via a php functon
Shortcode Empty Paragraph Fix

Solution:

This issue occured because when shortcodes are embedded in a block of content that is filtered by wpautop.

Just insert this code in your functions.php file:

function boot_shortcode_empty_paragraph_fix( $content ) {

      $array = array (
          '<p>[' => '[',
          ']</p>' => ']',
          ']<br />' => ']'
      );

      $content = strtr( $content, $array );

      return $content;
}

add_filter( 'the_content', 'boot_shortcode_empty_paragraph_fix' );

Wordpress