Shortcodes are one of the most powerful features in WordPress
The WordPress codex summarized the use of shortcodes as: shortcode = shortcut.
This does not begin to explain the power and usefulness of shortcodes. To begin, lets look at a few examples where we would use shortcodes:
- Your theme requires specific content, such as call-outs or quotes to be wrapped in html, such as DIV tags with specific CSS classes. The TinyMCE editor in WordPress may strips those out, or non-technical users don’t remember to add the html, or do it wrong.
- You want to display specific information, such as content from the logged-in user’s profile in a page or post. This information will not appear unless the user is logged in, and will be different for every user.
- You want to retrieve information from another web site, like Twitter or Facebook, and display it inline with the normal content of a page or post.
These are just a few simple examples, but they serve to illustrate the range of possibilities.
A shortcode is a WordPress-specific code that can embed files or create objects that would normally require repetitive strings of HTML or CSS. A shortcode is a descriptive bit of text wrapped in square brackets, e.g. [donatebutton] – which can be inserted anywhere in your WordPress site. Shortcodes let authors and editors invoke functions by inserting a tag into the content of a page, post, or widget. There is virtually no limit to what can be done with shortcodes and their associated functions. Shortcodes are often dropped into your WordPress post to insert a ‘Call to Action’ button. When you implement shortcodes, you are able to call regularly used pieces of code in seconds, avoiding tedious repetition, while decreasing the chance of common, unforgiving typing errors.
To create a shortcode, you write a PHP function, which is a stand-alone block of code, typically placed in the functions.php file, that contains all the programming logic to do what you require. You then assign a name to it – its shortcode – so that it can be referenced inside a page, post, or widget.
Shortcodes can be very simple, or extremely complex. Anything that WordPress and PHP can do can be made into a shortcode.
What the user sees, however, is easy to remember and use. Shortcodes have 3 basic formats. You determine which format you want when the shortcode is written. These formats are:
[shortcodename]Some text you want to be part of the formatting[/shortcodename]
When WordPress encounters a shortcode in a page, post, or widget, it passes any options or enclosed text to the function. That function code executes and returns the results, if any, back to WordPress, which then removes the shortcode and replaces it with the results.
Since being introduced with WordPress 2.5, the WordPress Shortcode API has become the go-to resource for fast and easy customization of site layout and inserting certain formatting snippets. WordPress has a very easy function called do_shortcode() that lets you add shortcodes in your themes. For a detailed explanation of how to use shortcodes for creating and customizing WordPress themes and sample shortcodes go to: http://codex.wordpress.org/Function_Reference/do_shortcode
For specific shortcode snippets and how to use them go to:.https://handsonwp.com/category/knowledge-base/wp-snippets/shortcodes/