Skip to content

Instantly share code, notes, and snippets.

@corypina
Last active August 29, 2015 14:26
Show Gist options
  • Save corypina/75639ff61d53564a0ff6 to your computer and use it in GitHub Desktop.
Save corypina/75639ff61d53564a0ff6 to your computer and use it in GitHub Desktop.
Wordpress shortcodes will sometimes output empty <p> tags. This plugin will remove them. Source of original code: https://thomasgriffin.io/remove-empty-paragraph-tags-shortcodes-wordpress/
<?php
/*
Plugin Name: Shortcode P-Fixer
Description: Remove empty paragraphs from shortcode output.
*/
/* Original Code from Thomas Griffin
/* https://thomasgriffin.io/remove-empty-paragraph-tags-shortcodes-wordpress/
*/
add_filter( 'the_content', 'tgm_io_shortcode_empty_paragraph_fix' );
/**
* 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 tgm_io_shortcode_empty_paragraph_fix( $content ) {
$array = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
return strtr( $content, $array );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment