Get the Official WPSaviour App Now!

Tips

Clean Up WordPress Shortcode Formatting

As I used to be engaged on a brand new premium WordPress theme for Themeforest I used to be having points with my Pricing Desk shortcode because it saved including further spacing attributable to stray empty paragraph (p) tags that have been being added robotically by WordPress. Doing somewhat looking out I discovered an amazing answer on the TF discussion board.

Clear Up WordPress Shortcodes Perform

Merely copy and paste the next code into your features.php file or wherever your maintain your shortcodes. This perform will clear up the output of your shortcodes, which is particularly vital for nested shortcodes.

if( !function_exists('wpex_fix_shortcodes') ) {
	perform wpex_fix_shortcodes($content material){   
		$array = array (
			'<p>[' => '[', 
			']</p>' => ']', 
			']<br />' => ']'
		);
		$content material = strtr($content material, $array);
		return $content material;
	}
	add_filter('the_content', 'wpex_fix_shortcodes');
}

What it does…This piece mainly grabs all of the publish content material earlier than it’s outputted and replaces particular code as talked about under:

  • All situations of <p>[ are replaced with [ – Removes opening paragraphs before shortcodes
  • All instances of ]</p> are changed with – Removes closing p tags after shortcodes
  • All situations of ]<br /> are changed with – Removes breaks after shortcodes

Download The WPSaviour App Now

Related posts
Beginner’s GuideBlogTips

Magento vs WooCommerce – Which one is Better? (Comparison)

Beginner’s GuideBlogTips

12 Best Calculator Plugins for Your WordPress Site

Beginner’s GuideBlogTips

How to Buy a Domain Name That is Taken (9 Pro Tips)

Beginner’s GuideBlogTips

Top 5 free payment gateway plugins for WordPress in India (2020)

Sign up for our Newsletter and
stay informed

Leave a Reply

Your email address will not be published.

Fear Of Missing Out?

Sign up with your email address to receive WordPress tips and updates
SUBSCRIBE NOW
Terms and Conditions apply
close-link
Click Me