Shortcodes are a very popular tool in WordPress that allow users to easily add content generated by plugins or themes to any page or post without needing to be familiar with PHP code and editing theme template files. As they are very simple to create, shortcodes can also be used to easily automate the output of content that repeatedly needs to be included in your site's content.
This recipe explains how to create a new custom shortcode that will be used to quickly add a link to a Twitter page in any post or page, automating a repetitive task.
- Navigate to the WordPress plugin directory of your development installation.
- Create a new directory called
- Navigate to this directory and create a new text file called
- Open the new file in a code editor and add an appropriate header at the top of the plugin file, naming the plugin
Chapter 2 - Twitter Shortcode.
- Add the following line of code to declare a new shortcode...