Have you heard of WordPress Shortcodes? This could easily be one of the BEST things you implement on your website to save yourself time.
As online business owners, most of us have some text, images, or code that we reference often in blog posts. For many, this is an affiliate disclosure.
While it’s easy enough to pull from your Trello board or another blog post, you will eventually run into a problem where you’ll want to make a change. Now, you’ve got to go back and update TONS of old posts.
After one too many times of this happening to me, I went seeking a solution. Introducing: WordPress shortcodes. A shortcode is one word in brackets that ‘calls’ for something else in its place.
Using the same disclosure example as above, you put the shortcode in the spot you want it in the post. What actually appears there is edited somewhere else where it can be edited once, regardless of how many places it appears.
You aren’t just limited to using WordPress shortcodes for an affiliate disclosure either. On a former blog of mine, I created one to use at the bottom of every blog post that listed a few of my current favorite amazon products. I could update what displayed there whenever I wanted without having to update every post.
Ways to use WordPress Shortcodes
You can use WordPress shortcodes for anything, but here are a few things you may be doing that could be replaced by a shortcode.
- Affiliate disclosure
- Signature (image or written sign off)
- Favorite products/tools spotlight
- Email opt-in (if your provider doesn’t provide a plugin that does it)
- Popular lead magnet
- Link to a post/page you reference frequently
- Author Bio
- Other posts you may love (by category)
How to use Wordpress Shortcodes
I know how busy you are, and I want to help. Copy the below WordPress shortcode code and a completed WordPress shortcode for your affiliate disclosure.
function get_REPLACE-WITH-SHORTCODE-NAME($atts) { return 'REPLACE THIS WITH WHAT YOU WANT TO APPEAR'; } add_shortcode('REPLACE-WITH-SHORTCODE-NAME', 'get_REPLACE-WITH-SHORTCODE-NAME');
You’d replace ‘REPLACE-WITH-SHORTCODE-NAME’ in all 3 places with the name of your shortcode. In the example below, I use ‘disclosure’. Then you’d replace ‘REPLACE THIS WITH WHAT YOU WANT TO APPEAR’ with what you want to appear. In the example below, it’s the disclosure.
function get_disclosure($atts) { return 'Some links on this page may be affiliate links. This means, at no cost to you, I may earn a commission.'; } add_shortcode('disclosure', 'get_disclosure');
Now that you have the snippet written, it’s time to install. I’m providing both written directions and a video overview for this tutorial. Don’t mind the old branding as this is a very old video.
In your WordPress menu, select ‘Appearance’ and then ‘Editor’. From there, click on your ‘Functions.php file’, which is usually named ‘Theme Functions’.
IMPORTANT! An error in your functions.php file can take your site down. Be sure to copy and paste the current functions.php into a text file (like notepad) and save it as functions.php so you can quickly upload using your host’s file manager in the event that something gets messed up.
Scroll to the very bottom of the file and add a few lines of space using the ‘enter’ or ‘return’ button on your keyboard. Paste the code I’ve provided or create your own, and hit save.
Now, in your blog posts, you can call in this piece of code by using the brackets around the name of the code. So for example, [TESTING].
Seriously, that’s it.
Scared of touching code? Search for shortcode WordPress plugins (like this one)! There are tons out there, I just personally found this DIY method quick and easy.
Good luck and I can’t wait to hear how much time you’ll save!
Additional resource: WordPress Shortcode API overview
(This post was originally published on 11/20/16 and has since been updated.)