Sometimes empty P tags occurs issues in design. So we need to remove empty p tags from custom shortcode in WordPress. Herer we will see how to remove theme.

Put the following code in function.php file. function.php file is located in root directory of the active theme folder.

add_filter("the_content", "remove_p_content_filter");

function remove_p_content_filter($content) {

	$block = join("|",array("shortcode1","shortcode2","shortcode3"));

	$rep = preg_replace("/( <p> )?\[( $block )(\s[^\]]+)?\](<\/p>|<br \/>)?/", "[$2$3]", $content);
	
	$rep = preg_replace("/( <p> )?\[\/( $block )](<\/p>|<br \/>)?/","[/$2]",$rep);

	return $rep;

}

Now the empty tags will be removed from the shortcodes. Enjoy the coding. 🙂

There are currently no comments.