Understanding WordPress Shortcodes

| By Webner

Introduction To WordPress Shortcodes and How to Use them

What is a shortcode?
A shortcode is a WordPress-specific code that lets you do effective things with a very little effort. We can embed the files or can create objects that would normally require lots of complicated and huge code in just one line that is there’s no need for users to manually write code into a post content. We can say a shortcode is a shortcut pointing to a code for some functionality.

There are so many inbuilt shortcodes in a wordpress theme and there are plugins which have their own shortcodes like gravity forms, contact forms, woocommerce etc. But you can also create your own shortcodes.
For example

here gallery is the shortcode tag and the ids, order,orderby and columns are shortcode attributes. These attributes basically determine the returned HTML code.

How to use shortcodes?

The shortcodes are usually enclosed in the square brackets ([ ]). And to use these you can simple paste them into the site, these are generally placed in the posts or pages. Theme have many shortcodes that come along with it and some are part of the plugin when can be used when the plugin is activated on your site.

You can find the shortcodes that you want to use and compatible to your theme and plugins in their documentation. I am using the woocommerce current user shortcode example here. Check the screenshot below

I have place it in a page named “My account” and hence you will find the following html on this page in the site.

You can use more than one shortcode in a single page of your site. However, they can go into any location where you can add code through the WordPress editor.

And hence the output will be

That is first we have added the gallery shortcode and second is woocommerce current user account and so the output is.

There is one thing to note about the shortcodes that is “If you use shortcodes that come along with your theme, or as part of a plugin, those shortcodes will stop working if you ever switch themes or disable/uninstall the plugin”.

Leave a Reply

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