This article describes how to create and use custom shortcodes in WordPress.
Shortcodes are useful when you have to add dynamic or repeatable content to multiple areas of a WordPress site. By editing a shortcode, you can quickly change content in multiple areas of your site simultaneously, instead of editing multiple pages individually.
Creating and using a shortcode
To create and use a shortcode in WordPress, follow these steps:
-
Log in to WordPress as the administrator.
-
On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:
-
In the right sidebar, under Theme Files, click Theme Functions (functions.php).
-
Copy the following code snippet and then paste it at the bottom of the functions.php file:
-
Click Update File. WordPress saves the changes to the functions.php file.
-
The shortcode is now enabled. To use it, open a post or page on the site, and then type
[my_custom_shortcode] where you want to display the shortcode message text. For example:
Save your changes, and then view the post:
You can create as many shortcodes as you want, as long as they have unique names in the functions.php file.
For more information about shortcodes in WordPress, please visit https://wordpress.com/support/shortcodes.
Related articles