As a blogger or programmer, we probably come across an awkward situation when we write content or hard code for our website. This situation is that we’ll create a lot of frequently used content such as links, images, advertisement banners, etc.
The problem for this embarrassing situation is that we have to repeat to apply the same codes used to create those contents over and over again. This definitely results in repetitive works that lead to mistakes easily.
Fortunately, a WordPress feature called shortcodes come to the rescue and helps us out of this uncomfortable situation.
WordPress shortcodes are shortcuts for those complicated and repeated codes and can be placed anywhere in your website.
A shortcode can be written in a descriptive bit of text wrapped in square brackets.
To implement such shortcodes, we need to create them in the functions.php file in your WordPress theme. For this example, the following function will convert [resource] shortcode into a link to my site’s resource page:
<?php // shortcode for resource page link
function myResourcePage() {
return '<a href="http://www.firstsitesolutions.com/resource-page/" title="Resource Page ">Resource Page</a>';
}
add_shortcode('resource', 'myResourcePage');
?>
After you create this shortcode in your WordPress theme’s functions.php, you can apply this function by simply write and insert “[resource page]” anywhere in your blog that you want this link to appear.
It just likes magic!