For the WooCommerce user it couldn’t be easier to set up an online shop and begin selling with very little development knowledge. The easy to use interface offers heaps of layout and customisation options all easily accessible for the novice website owner.
That said, can you imagine the world of possibilities for those with some programming knowledge? Thanks to the WooCommerce built in shortcodes, there’s literally a limitless array of configuration options. Although we won’t go into the technical detail of using these shortcodes, this article sheds some light on the concept of this impressive programming solution.
Shortcodes are a basic function not only found in WooCommerce but in WordPress too. These are a type of macro code where a certain function can be implemented in pages or posts.
As WordPress only offers a limited number of shortcodes as standard, many users are left using the shortcodes of themes for added flexibility. This gives way more options than that of the WordPress Editor.
For those looking to increase their knowledge of shortcodes, there are plenty of useful resources in the posts ‘Shortcode’ and ‘Shortcode API’ found in the Codex.
Simply shortcodes & parameters
Most shortcodes are written within square brackets. As an example, a shortcode may be [ gallery ] which would show all images that are associated with a page or an article via the image library.
These shortcodes have parameters which determine certain aspects of the layout. That ‘gallery’ shortcode may include the parameters ‘order’ and ‘orderby’ to assign further conditions. Here’s how you would ensure images are shown in descending order from new to old:
[ gallery order=”DESC” orderby=”post_date” ]
Creating your own shortcodes
As with most applications in WordPress, there is all the functionality you need to extend and build upon the system. By using the Shortcode API you’ll be able to create shortcode for use in pages and posts. This simply requires some basic PHP and HTML knowledge.
Two fundamental functions are needed including a ‘callback’ and ‘callback’ function. The latter generates shortcode from the former via ‘add_shortcode’ which features two parameters; the name of the shortcode and the name of the callback function.
From here, the code can be added to the functions.php file of your theme.
WooCommerce Shortcode Plugin
At one time there was an easy way to use shortcodes in WooCommerce thanks to a handy ‘shortcode’ function. This bypassed the need to read through endless manuals to add shortcode. Unfortunately, that tool is no longer available on recent updates but you can still enjoy this extra by installing the
WooCommerce Shortcodes plugin.
After installing the plugin, a new option should appear in the editor allowing you to play around with certain shortcodes.
As mentioned, this approach is more orientated for those with experience in programming as opposed to the part-time blogger and small e-commerce site. However, by learning some of the basic PHP shortcode methods, you can unlock a whole world of customisation features.