Shortcodes were introduced in WordPress 2.5 and are used for adding macros to a page or post.
There are several built in shortcodes like the Gallery shortcode that come with WordPress, but you will encounter Shortcodes most often after you install plugins.
Shortcodes are designated using square brackets. So to insert a picture Gallery into a post,you enter the following into the post:
Most shortcodes consist of a single tag, but some shortcodes require a closing tag. The caption shortcode is:
Notice the closing tag uses the backslash just as in HTML tags
The best way of understanding shortcodes is to see it in action.
So we are going to look at the contact form shortcode.
Here are the instructions for the FS contact form:
This is how I add it to a page or post
This is what the page visitor sees
You can see that the shortcode has been replaced by the actual contact form.
Common Questions and Answers
Q- Can I create my own shortcodes?
A- Yes but you need a knowledge of the WordPress code and php.
Q- Does the visitor or search engine see the shortcode.
A- No they see the contents of the shortcode.
Shortcodes are macros that can be used for adding various objects like contact forms, polls etc to a web page.
WordPress comes with some shortcodes but in the main, you will encounter them when using plugins.
With a little basic programming knowledge you can easily create your own shortcodes.
Related Tutorials and resources:
- Built in Shortcodes – Note: this are for the self hosted WordPress, not the hosted sites on WordPress.com which has many more shortcodes.
- Smashing Magazine- Complete guide to shortcodes
- Understanding the WordPress Query-Beginners Guide
- WordPress File And Directory Structure Explained
- PHP Callbacks and Callback Functions
- Beginners Guide to WordPress Templates
- Beginners Guide to the WordPress Loop
- The WordPress Load Process-Beginners Guide
- Understanding and Editing the wp-config.php File