Last active
August 29, 2015 14:26
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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