If you’ve procured a website from spamzilla.io and have revamped it a couple times then you know exactly what “naked shortcodes” are. This post explains what they are, how to clean them out, and alternatives for shortcodes in your content. Naked shortcodes are shortcodes that all your website viewers can see and read plain and… Read more Cleaning Out Your Naked Shortcodes
If you’ve procured a website from spamzilla.io and have revamped it a couple times then you know exactly what “naked shortcodes” are. This post explains what they are, how to clean them out, and alternatives for shortcodes in your content.
Naked shortcodes are shortcodes that all your website viewers can see and read plain and clearly. They’re embarrassing. It’s like having someone listen to you singing in the shower, or seeing your un-formatted non-production ready code before you ship it.
Naked shortcodes happen most often when you do a site re-vamp that involves switching from a theme or deleting plugins that had their own unique shortcodes for displaying content. Basically, you were using the shortcode to display something, but now you found a better way to do that, but those shortcodes are still in peppered throughout your posts and pages. Now you’ve got to get rid of them.
The biggest problem with naked shortcodes is finding them. You might not remember exactly what the shortcode was exactly, and even if you did you wouldn’t remember all the posts and pages where you used it. So how in the world can you clean up something you can’t find reliably or quickly?
Enter the “Shortcodes in Use” plugin. This is a great little tool that scans your site for any and all shortcodes that are being used and lists the occurrences so you can go and kill them on site!
The great thing about this tool is you can narrow the results very specifically to what you’re looking for. Of course you can search for every instance of a specific shortcode that you know, but it also has the perfect setting for our topic of cleaning up naked shortcodes.
If you are looking for any shortcode that isn’t registered from a currently activated plugin or your theme, you can choose to search by “Unknown”. Since most likely the shortcode was used in a page or post, you can also limit it to search only in the content, and just pages and posts. I just did this recently on my website and I was really amazed at how quickly the search results populated in my admin.
WPBeginner has this nice post about finding and removing unused shortcodes and they provide code which I’ve used on this site as well. The shortcoming to that method is that you have to know the name of the shortcode you’re looking for. “Shortcodes in Use” helps you get around that.
What About Just Overriding the Shortcode?
There is a way that you can basically hijack a shortcode and force it to output nothing at all. I’ve heard developers recommend this rather than actually cleaning up the usage.
I’d never recommend this. It’s just lazy and sloppy. The shortcode is still registered, gets additional logic applied to it, and then runs on the pages or posts as well which in the end just slows down your site.
If you care about your site, take the time to do it right; just like you would with your car or your home.
How to Prevent Naked Shortcodes
Ideally, rather than deal with all this clean-up, why don’t we just avoid naked shortcodes completely? In a perfect world, our plugins would never changes, shortcodes wouldn’t be registered in your theme, and every plugin you install would be your best buddy for the rest of your website’s existence. Unfortunately, life doesn’t work that way.
So to prevent or avoid naked shortcodes, we have to think pro-actively about how we use shortcodes on our website. To do that, we need to understand shortcode usage a little more broadly.
While plugin authors continue to find more and more ingenious ways to use shortcodes, using them in your content typically fall into a couple major categories:
- Necessary Shortcodes. The main purpose of the plugin is executed with a shortcode, like a form, or e-commerce products, or a gallery, a google map. These all only work if the shortcode is inserted into the page.
- Functional Shortcodes. These are shortcodes that do something with your content, like display user information, or hide content for non-logged-in users, or based on time, date, or even geography.
- Aesthetic Shortcodes. These typically come in giant bundles of shortcodes. Like “1,000 Amazing Bootstrap Shortcodes you can’t live without”. They give you alerts, or buttons, or even columns in your content.
There’s certainly many more categories of shortcode usage than this, but this is a good starting point.
Preventing Naked Shortcodes Strategically
Avoiding naked shortcodes with necessary shortcodes is not overly difficult. Primarily because if you are changing your site to an entirely new e-commerce platform, that’s a major overhaul and you’ll likely be going over the whole site with a fine tooth comb anyway.
But something like a Gallery might be more regular and challenging. One way to make your life easier in this case is to leverage either your “Post Formats” or tags to indicate whether or not a post has a gallery in it or not. That way, when you want to swap it out, you can sort your posts by that format or tag and then go through systematically replacing the old gallery with a new one.
This method isn’t fool-proof since you could easily forget to update the post format or add the correct tag, and neither of those apply to pages at all. But this strategy would help minimize the cleanup with the “Shortcodes in Use” plugin at least.
Sometimes you might want a shortcode output at the end of all your posts. Rather than type it in manually for every post, add it into your theme’s template file, or use the
the_content() filter to dynamically add it. This allows you to replace that shortcode once and affect your entire website.
Prevent Naked Shortcodes by Avoidance
The best way to prevent naked shortcodes is to simply avoid using shortcodes as much as possible. This won’t apply of course to necessary, or functional shortcodes, but I’d be willing to apply this method to the “Aesthetic” category completely.
I wrote a while back on creating styled content in the editor. Since then, I’ve used that method many times and it continues to be the absolute best way to style content inside the editor for me. The styles are very easily portable between themes and could also just be added to a functionality plugin instead.
I have not yet tried to implement columns with the editor-styles method, but I’m certain it would work just as well.
Avoidance can also apply to plugins that use necessary or functional shortcodes though too. For example, Visual Composer only works and can only execute it’s functions via shortcodes. My advice with this is crystal clear: AVOID IT! Beaver Builder is an excellent page builder that once deactivated will not leave a mess of shortcodes all over your posts and pages.
In a Nutshell
Overall, I recommend evaluating closely whether or not a plugin which is heavily shortcode based is absolutely necessary to your site or not. If you are going to be using shortcodes in your posts specifically, be strategic about how you manage those posts in case you need to clean them up later.
Lastly, if you can avoid using the shortcode completely, that would be best. Rather than just install another plugin and start pasting shortcodes everywhere, take some time to research alternatives. The easy way may seem easy now, but it’ll cost you dearly at your next site re-vamp.