I just discovered the beauty of working with WordPress shortcodes and the the frustration that can come along with it. If you’re building websites for clients, it can mean the difference between repeat calls about them breaking code in the backend and the peace and quite of a satisfied client who knows how to edit their content.
If you’re working with shortcodes, you’ve no doubt come across phantom <br> or <p> tags. WordPress automatically adds these in with the wpautop() function. These tags can effectively break your carefully coded content and cause you hours of frustration, not to mention calls from your clients.
Fortunately for you there’s an easy fix to the problem. We could just do away with the wpautotop() function, but that would cause a lot of other issues within the visual editor, a big problem when working with client sites. However with a simple php function we can eradicate those return and paragraph tags in your carefully coded shortcode content. In your theme’s functions.php file before your shortcodes, insert the following code:
[codebox 1]
And then add this line into your shortcode function or functions:
[codebox 2]
Voila! You’re done. Now go test your now finally working shortcode.
Thanks goes to Donal MacArthur for this incredibly useful bit of information.
Comments are closed.