Not quite long, we got a request from one of our followers asking for a tutorial on how to use Shortcode in their WordPress theme. Shortcode is a unique tag you can insert into a post which gets replaced with specific contents when you actually view the post on your website/blog. You’ve already used the built in shortcode in WordPress if you’ve previously embedded a WordPress gallery on your blog. You can check our tutorial on how to add shortcodes to WordPress theme here.
Let’s go pay shortcode a visit!
Fortunately, WordPress has an extremely simple function called “do_shortcode( )” that allows you to add shortcodes in your WordPress theme. You can easily add the code like this:
<?php echo do_shortcode(“[example_shortcode]”); ?>
This tutorial will, however, teach you how to use shortcodes, examples of shortcodes currently in use, and the reason why they exist.
How to Use Shortcodes in WordPress
As earlier said, shortcodes give you means of adding special content in a post or page with a tag. For instance, users are given a shortcode for them to be able to add a contact form to their website when they use Simple Basic Contact Form plugin. This shortcode is something like this:
All users are expected to do is to simply copy and paste or rather tag this code into the contents of a page or post. If the Simple Basic Contact Form plugin is installed on your WordPress website, a contact form will be displayed at the front end of the site.
All plugins or theme supporting shortcodes will provide you dedicated shortcodes for you to copy and paste for specific contents to be displayed.
Why do we use shortcodes?
From a developer’s perspective, visualize creating a plugin which allows users to create a contact form. You can make them add the contact form to their site by either making them publish a distinct contact page or have them paste a shortcode anywhere on their WordPress page, be it within page or post. By opting for the latter method, they can display other content below or above the form, call it another name apart from “contact”, or even add the same form to different page or post.
Logically, the best thing to do is give them the option of utilizing a shortcode. Shortcodes are very flexible and can be used to place any content from a theme or plugin anywhere you deem fit.
Shortcodes currently in use
For you to have a better idea of how useful and unbelievable shortcodes can be, here are a couple examples of currently used shortcodes:
The Meta Slider plugin allows you to create and add amazing sliders to your WordPress website. The plugin gives you shortcode for every slider you create and you can place the shortcode anywhere on your site.
WP Google Maps
WP Google Maps allows you to add customized Google Maps embeds to your page or posts. Every time you create a custom Google Map, the plugin give you a usable shortcode.
The Shortcodes Ultimate plugin utilizes shortcode’s power to grant you accessibility to a large number of graphical elements. From image sliders to buttons, you can use over 50 different shortcodes packaged into this plugin which can be used to add different graphics within your content.
That does it! Now you know the power of shortcodes and how effective they can make your work on WordPress be. If you’ve not been using shortcodes, you now have a million reasons to start doing so. You can tell us what you did with shortcodes on your WordPress site in the comment box. We also have a tutorial on how to duplicate pages in WordPress. This will come in handy when you least expect.