ThemeForest not too long ago up to date their WordPress theme submission necessities to be extra stringent and extra inline with WordPress theme improvement finest practices.
The rules require the use a number of of WordPress’ core options, normal theme hooks, and disallow PHP features (like base64 and fopen) that actually shouldn’t have ever had anywhere in a WordPress theme to start with.
Mainly, just about WordPress.org’s Theme Assessment coverage, give or take just a few issues.
Total, it’s a step in the precise route and strikes to promote finest practices on one of the crucial common WordPress theme marketplaces on the web. There’s only one drawback…
One factor that notably caught my eye, nevertheless, was how sure “admissible” shortcode performance was allowed (i.e. by straight together with them by the theme’s
features.php file). Those listed as “admissible” included the next:
- pricing tables
- picture containers
Inadmissible shortcodes embody: maps, accordions and toggles, boxed contents, column, contact kinds, charts.
The Drawback with Shortcodes in Themes
I can’t actually put it higher than Justin Tadlock already has. One of the crucial noticeable points, is that when a person modifications themes, the shortcodes will now not be parsed.
Let’s say “Tremendous Superior” theme had a shortcode function that might output a giant inexperienced button with a hyperlink if you typed out one thing like
Large Inexperienced Button
Whenever you swap to a different theme (let’s face it, folks get tired of themes simply), there’s no extra massive inexperienced button. As a substitute, you see the unparsed shortcode within the put up as if it have been some other piece of content material, like this:
It appears to be like ugly, complicated, and out-of-place, and it’s a ache for the person to return and take away/substitute all of them.
The Different Drawback with Shortcodes in Themes
One thing that Tadlock went over in his “Coping with shortcode insanity” article is, lots of shortcodes are so easy and HTML-like, it would even be finest to instruct customers to write down out just a little (*gasp*) actual HTML code.
shortcode in my instance above may very well be simply rewritten as one thing like:
Button textual content right here
Whereas there will not be CSS code styling the
.button selector in a brand new theme, at the very least a standard hyperlink will present up. Which is a giant enchancment over an unparsed
shortcode displaying up in a put up’s content material.
Plus, I imagine each WordPress person ought to have at the very least some fundamental understanding of HTML code. By educating them, even in little bits (like how one can assemble a hyperlink), will assist. If they will perceive a shortcode, it received’t take way more to get them to grasp fundamental HTML.
However The Customers Don’t Care!
A typical argument I see defending all types of dangerous practices in terms of theme improvement is that the customers merely don’t care. I imply, possibly they by no means need to replace their theme, during which case, this shortcode concern can be a moot level.
The issue is, some customers inevitably will need to swap themes some day. Some customers will need to set up a plugin which may battle with another poorly-thought-out code in a theme.
Then, they in all probability will care, and possibly will surprise if the theme they purchased with 100s of built-in shortcodes and different superfluous options was actually value it.
The Proper Technique to Embrace Shortcodes
Put it in a plugin. A extremely easy plugin. It doesn’t want a separate choices panel. Simply actually copy and paste no matter you have been going to incorporate by way of your theme’s features.php file, and put it in a plugininstead.
It may even be bundled with one thing like TGM Plugin Activation to make it required on theme activation. Or not. A theme remains to be a theme with out shortcodes.
This fashion, if the person modifications themes, the shortcodes will nonetheless work, as a result of that performance is dealt with by the plugin that’s nonetheless lively.
Possibly the plugin may additionally enqueue kinds for the shortcodes as nicely. This fashion, the large inexperienced buttons you included with the
shortcode will nonetheless be massive inexperienced buttons, whatever the theme used.
Why Did ThemeForest Permit “Admissible” Shortcodes?
It’s arduous to say what precisely the reasoning behind this determination was. Japh Thomson, a WordPress evangelist at Envato (ThemeForest’s father or mother firm) had this to say about it in a touch upon WPMU.org:
Complicated shortcode performance actually ought to reside in a plugin, not a theme. It additionally simply is smart when you think about most of our authors have a number of themes.
Clearly, he will get it. So it’s a thriller to me why there can be any “admissible” shortcodes in any respect. And sure, I notice he used the phrase “complicated” within the quote above, and the admissible shortcodes do are usually fairly easy ones (dropcaps, lists, and many others.).
Easy as a shortcode could also be, the issues I outlined above will nonetheless exist. ThemeForest has proven to be aware of group suggestions, so it’s attainable this rule is amended sooner or later.
Spoiler alert: Didn’t get any responses to that tweet with an actual instance of a shortcode completely needing to be included in a publicly-released theme.