Snippets

Joey Hernandez WordPress - Shortcode Empty Paragraph Fix

Created by Joey Hernandez
<?php
/**
 * Filters the content to remove any extra paragraph or break tags
 * caused by shortcodes.
 *
 * @since 1.0.0
 *
 * @param string $content  String of HTML content.
 * @return string $content Amended string of HTML content.
 */
function shortcode_empty_paragraph_fix( $content ) {
	$array = array(
		'<p>['		=> '[',
		']</p>'		=> ']',
		']<br />'	=> ']'
	);
	return strtr( $content, $array );

}
add_filter( 'the_content', 'shortcode_empty_paragraph_fix' );

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.