Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created March 31, 2021 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/8969bb6e1cedb9be92140cc2efa9febb to your computer and use it in GitHub Desktop.
Save wpscholar/8969bb6e1cedb9be92140cc2efa9febb to your computer and use it in GitHub Desktop.
WordPress plugin to remove empty paragraph tags from shortcodes in WordPress.
<?php
/**
* Remove Empty Paragraph Tags
*
* @package RemoveEmptyParagraphTags
* @author Micah Wood
* @copyright Copyright 2021 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Remove Empty Paragraph Tags
* Plugin URI:
* Description: Removes empty paragraph tags from WordPress.
* Version: 1.0
* Requires PHP: 5.6
* Requires at least: 5.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* Text Domain: remove-empty-p-tags
* Domain Path: /languages
* License: GPL V2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Removes empty paragraph tags from shortcodes in WordPress.
*
* @param $content
*
* @return string
*/
function tg_remove_empty_paragraph_tags_from_shortcodes_wordpress( $content ) {
$toFix = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
return strtr( $content, $toFix );
}
add_filter( 'the_content', 'tg_remove_empty_paragraph_tags_from_shortcodes_wordpress' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment