What to do about shortcodes?

I recently read a wonderful post by Justin Tadlock where he outlined the various problems associated with going overboard with shortcodes. The biggest problem he identified was that by using a theme’s shortcodes, you are essentially locked into using one of their themes forever as once you switch themes the special formatting is gone and you are left with stray shortcodes in your posts. While you could just edit each post and remove all the stray shortcodes there has to be a better way. WordPress is loved for it ease of use and special features shouldn’t be added in a way that tarnish that reputation.

Lately I have been trying to think more long term about WordPress themes. While every theme developer wants to believe that they are going to have a customer for life it is important to think how your development decisions will affect your users in the future, especially if they switch to another theme.

Then I ran across a post by Alison Barrett who offered an alternative to shortcodes. Her idea was instead of using shortcodes in her Bolts parent theme she would add new styles to the TinyMCE styles dropdown in the visual editor. By utilizing this method while you will still lose the formatting when you switch themes the correct html will be in place and there will not be any stray shortcodes in your posts, the code will degrade gracefully.

Also in order to provide easy transferal of the css for the html code generated by the styles dropdown I would make sure to have a separate stylesheet (which Alison did) or at least a clearly marked portion of your regular stylesheet that has all the custom styles. Then when the user switches themes all they have to do is transfer over that css and all their previous formatting will be preserved.

Does this method make sense? Any other pros/cons?

2 thoughts on “What to do about shortcodes?

  1. Thanks for the shout-out! I wrote that post as a reaction to Justin’s. I had tons of custom shortcodes in Bolts, and after reading his post I came up with a different option.

    I did separate the CSS to put all the Bolts-specific styles in their own stylesheet—it’s definitely the way to go.

    1. Basically any time I want to know how to do something correctly I check out either yours or Justin’s blog and I usually find the answer. Keep up the good work and I can’t wait to see ThemeJack launch.

Leave a Reply

Your email address will not be published. Required fields are marked *