Skip to main content

WordPress Shortcodes: When & Where to Use

September 3rd, 2015

I hate accomplishing complex layouts with shortcodes. Flat out, it’s one of my least favorite things and it is unfortunately a major part of a lot of ThemeForest themes, which is probably a large part of why I stopped taking theme modification projects. I don’t feel like shortcodes are intuitive to the end users of WordPress and would much rather provide completely straightforward custom fields for users to manage their data with. Less room for errors, much more straightforward and it results in clients who see the beauty of how truly easy WordPress can make managing content.

BUT I do think shortcodes can be used effectively for certain stylistic elements… like a button. Throw a little:

function myCustomButton($atts, $content = null) {
  extract(shortcode_atts(array('link' => '#'), $atts));
  return '<a class="button" href="'.$link.'">' . do_shortcode($content) . '</a>';
}
add_shortcode('button', 'myCustomButton');

In your theme’s functions.php file and you’ve got yourself a nice little button shortcode that a client can use: [button link=”URL”]Button text[/button]

There are some little stylistic touches that I think shortcodes make sense to take advantage of in execution. I would just heavily advise against using them to be the major driving force behind executing all of your layouts.

MORE: WordPress Tutorials

Related Articles