Shortcodes in WordPress

I love WordPress.

The blogging platform is a great content management system (CMS) to run on your website. Not only as a blog, but it can host your entire site. For example, most of the info pages on Pristine are on WP. In fact over the past year or so, my team has been learning how to create themes for WordPress.

At Pristine, we are providing the training schedules course-wise and city-wise on our different pages viz., for CFA Level I page, we are giving the schedule for all cities where CFA Level I is being conducted, for the Mumbai page, we are giving the schedule for all courses which are being conducted.

It does not take a rocket scientist to figure that there is a lot of duplicate information (which needs to be constantly updated) on different pages. With 8-10 centers and 6-7 courses that means anywhere between 50 to 70 pages which need to be updated whenever the training schedule changes. What a nightmare!

That’s where Shortcodes come in. Shortcodes are essentially functions that you can call from the WordPress CMS. Those of you who have used WP in the past would know that the WP platform is very easy to publish content ensures that you can only enter HTML in the publishing mode. We cannot write PHP scripts within the WP pages.

One way is to customize your templates, but if you want to run the script within your WordPress Publishable Content, then Shortcodes is the elegant solution. All you have to do is declare a function in the theme’s corresponding functions.php file, declare your short code and bind that to your new function. Voila! Now you have your own short code!

So, in this example, all I have to do is create a filterable query for the training schedule and pass either the city or the course as an argument in all my pages. Every time the schedule changes, all I have to do is update it once in the database, and the content will get auto-updated in all my 50-70 pages.