If you have created shortcodes in WordPress, you may have noticed that when you get the content of your shortcode, it’s wrapped in html paragraph tags.
I don’t know why the progammers did that. It seems like a very bad idea to me to add formatting to the actual content.
I’ve found a post that presents this solution :
http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
But i’m wondering : Is there a solution proposed by the wordpress API itself, or something that i am missing here ?
The shortcodes, since they are inserted in the editor, comply to editor rules. Hitting the return in editor will generate a paragraph tag, just like any other text. It’s one of the TinyMCE features. To read more about TinyMCE check out their forum and especially this thread
The link in you’re question is now extinct, so I’m not sure of the solution it suggested, but here’s another solution for posterity:
Add the following to functions.php to run the formatting after shortcodes are evaluated:
The author notes that you’ll need to explicitly enable formatting within plugins that require it:
Simple solution which worked for me is to just remove paragraph end “</p>” from the beginning of the $content, and paragraph begin “<p>” from the end of the $content.
For example with regex like:
Or if you’re sure they’ll be there, you could just trim them like this: