The correct way to include shortcodes
Posted: Sun Dec 22, 2024 9:39 am
But users don't care!
A common argument I see defending all sorts of bad practices when it comes to theme development is that users just don't care . I mean, maybe they never want to update their theme, in which case, this shortcode issue would be a moot point .
The problem is that some users will inevitably want to change themes someday. Some users will want to install a plugin that might conflict with some other poorly thought-out code in a theme.
So, you will probably worry, and you will probably wonder if the theme you bought with hundreds of built-in shortcodes and other superfluous features was really worth it .
Put it in a plugin. A really simple plugin. It doesn't need a separate options panel. Just literally copy and paste what you were going to include via your theme's functions.php file, and put it in a plugin instead.
It could even be bundled with something like TGM Plugin Activation to make it required on theme activation. Or not. A theme is still a theme without shortcodes .
This way, if the user switches themes, the shortcodes will still work ,russian virtual mobile number because that functionality is handled by the plugin that is still active.
Perhaps the plugin could also enqueue styles for the shortcodes. This way, the big green buttons you included with the [button] shortcode will remain big green buttons, regardless of the theme used.
Why does ThemeForest allow “Allowable” shortcodes?
It's hard to say what exactly the reasoning behind this decision was. Japh Thomson, a WordPress evangelist at Envato (parent company of ThemeForest) had this to say about it in a comment on WPMU.org :
Complex shortcode functionality should reside in a plugin, not a theme. This also makes sense considering that most of our authors have multiple themes.
Obviously, he gets it. So it’s a mystery to me why there would be any “allowable ” shortcodes at all. And yes, I realize he used the word “complex” in the quote above, and allowable shortcodes tend to be pretty simple (dropcaps, lists, etc.).
No matter how simple a shortcode is, the problems I described above will still exist . ThemeForest has proven to be responsive to community feedback, so this rule may be changed in the future.
Conclusion
I realize this post seems a bit nitpicky , and these new guidelines are definitely a big step in the right direction. But there's really no reason why any shortcode should be allowed in a theme, simple or not.
Can you think of any situations where a published theme would need to include shortcode functionality via its own functions.php?
– Theme Lab (@themelab) July 9, 2013
Spoiler alert: I didn't receive any response to that tweet with an actual example of a shortcode that absolutely needs to be included in a publicly released theme.
That's because it's simply not easy for a user to go back and replace hundreds of button shortcodes after they switched to a theme that doesn't have exactly the same shortcode support.
A common argument I see defending all sorts of bad practices when it comes to theme development is that users just don't care . I mean, maybe they never want to update their theme, in which case, this shortcode issue would be a moot point .
The problem is that some users will inevitably want to change themes someday. Some users will want to install a plugin that might conflict with some other poorly thought-out code in a theme.
So, you will probably worry, and you will probably wonder if the theme you bought with hundreds of built-in shortcodes and other superfluous features was really worth it .
Put it in a plugin. A really simple plugin. It doesn't need a separate options panel. Just literally copy and paste what you were going to include via your theme's functions.php file, and put it in a plugin instead.
It could even be bundled with something like TGM Plugin Activation to make it required on theme activation. Or not. A theme is still a theme without shortcodes .
This way, if the user switches themes, the shortcodes will still work ,russian virtual mobile number because that functionality is handled by the plugin that is still active.
Perhaps the plugin could also enqueue styles for the shortcodes. This way, the big green buttons you included with the [button] shortcode will remain big green buttons, regardless of the theme used.
Why does ThemeForest allow “Allowable” shortcodes?
It's hard to say what exactly the reasoning behind this decision was. Japh Thomson, a WordPress evangelist at Envato (parent company of ThemeForest) had this to say about it in a comment on WPMU.org :
Complex shortcode functionality should reside in a plugin, not a theme. This also makes sense considering that most of our authors have multiple themes.
Obviously, he gets it. So it’s a mystery to me why there would be any “allowable ” shortcodes at all. And yes, I realize he used the word “complex” in the quote above, and allowable shortcodes tend to be pretty simple (dropcaps, lists, etc.).
No matter how simple a shortcode is, the problems I described above will still exist . ThemeForest has proven to be responsive to community feedback, so this rule may be changed in the future.
Conclusion
I realize this post seems a bit nitpicky , and these new guidelines are definitely a big step in the right direction. But there's really no reason why any shortcode should be allowed in a theme, simple or not.
Can you think of any situations where a published theme would need to include shortcode functionality via its own functions.php?
– Theme Lab (@themelab) July 9, 2013
Spoiler alert: I didn't receive any response to that tweet with an actual example of a shortcode that absolutely needs to be included in a publicly released theme.
That's because it's simply not easy for a user to go back and replace hundreds of button shortcodes after they switched to a theme that doesn't have exactly the same shortcode support.