WordPress shortcodes are a handy way to extend the functionality of what’s possible within the WordPress editor that are aliased to short strings of text that look [like-this].
There are a lot of things a shortcode can be used for, but typically it comes down to two main use cases:
- Custom Embeds — Plugins that allow you to embed things like contact forms or a Google map will often use shortcodes so a user can decide exactly where to put it on their site, or even stick it inside a post.
- Dynamic Content — Sometimes if something should be dynamic on the page, a shortcode can provide an easy way to do that. If someone wanted to show the current year as in some copyright information on a site for example, they could register a shortcode called “[current_year]” so it would show up on the site as “2021” without having to go in and edit the text every year.
Using shortcodes inside widgets
By default, WordPress will only look for shortcodes inside post and page content. But if you’d like to add a shortcode inside a footer, or sidebar, or any other text widget you can enable shortcodes in widgets with this filter:
Using shortcodes inside comments
You can also do this for WordPress comments. But keep in mind this filter is for the comment functionality native to core. Third party commenting systems like Disqus will not be impacted by this.
Using shortcodes in excerpts
Excerpts are an optional summary or description of a post. It’s the text that goes before the “Read more” link in the archive and blogroll pages of most themes.
Using shortcodes inside category, tag, and taxonomy descriptions
Not every theme using category and tag descriptions. But if yours does, and you want to use shortcodes in it, then use this code snippet:
Putting it all together
If you want to use shortcodes in all of those places, you can combine all the snippets into one site specific plugin for your site, or just install this plugin: