Shortcodes and Line Breaks in WordPress

This post may contain affiliate links. As an Amazon Associate I also earn from qualifying Amazon purchases at no cost to you. Full disclosure here.

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.

All-In-One Business Bookkeeping Spreadsheet

Share:

Facebook
Twitter
Pinterest
LinkedIn

Comments are closed.

More Good Reads

Related Posts

person in long sleeve shirt holding a calculator

What is the Easiest Bookkeeping Method for Small Business?

As a small business owner, keeping track of your finances doesn’t have to be complicated. The easiest bookkeeping method for small businesses is using a simple spreadsheet to record income and expenses. This straightforward cash basis method can save you time and headaches compared to traditional accounting. Why Use a Spreadsheet? Spreadsheets are easy to

two women sitting in front of computer monitor

Whale Hunting – The Risk of Having One Major Client

In 2012 we shut down our startup. It was devastating and emotionally draining. Walking away from something you’ve put your blood sweat and tears into is a gut wrenching experience. Fortunately we had a team with a skillset so we pivoted to being a software consulting business. Hooray, we’re saved! Very quickly we signed a

selective focus photography of hustle and bust text

Business Name Brainstorming – How-to Guide

If the idea of finding the right name for your business fills you with anxiety, you’re not alone. Business name brainstorming can be really challenging. Fortunately, there’s a formula that makes it easier. In my years as an entrepreneur, I’ve come up with at least a dozen brand names for companies I’ve started or co-founded,

Shopping Cart