You can add or execute a shortcode to a page or post in WordPress by going to the editor for that page and adding the correct syntax depending on the shortcode in question. I’ll give you several examples in this post today.
Table of Contents:
- What is a ‘shortcode’ in WordPress?
- Examples of adding a shortcode in WordPress Page Editor
- Adding a shortcode programmatically (for developers)
What is a ‘shortcode’ in WordPress?
A shortcode in WordPress is a bit like a placeholder for some more complicated functionality or content which you can ‘re-use’ in various different places on your site by simply adding the ‘shortcut’ to that more complex code to any page or post. The ‘shortcut’ is what’s known as a ‘shortcode’.
Examples of adding a shortcode in WordPress Page Editor
You can add a shortcode in a page or post content by going to the particular editor page for that page or post and adding the correct syntax as below.
Example 1: Simple shortcode
Add the below to your editor as a paragraph and then save. Replace the name of the shortcode with that of the particular shortcode you need to use.
[nameOfShortCode]
Example 2: ‘In between’ Shortcodes:
Some shortcodes help you to ‘wrap’ additional content in between them and can sometimes be used like this. NOTE: They have to be designed in this way however so check it can be used like this.
Replace the particular shortcode names with the specific ones you are using
[firstShortcodeName] you could add some plain text here in the editor which would be presented to the user on the front end in between whatever code is represented [lastShortcodeName]
Example 3: Shortcode with parameters
Sometimes a shortcode can have one or more parameters to customize the results of the shortcode funcitonality. You can add specified parameters as per the below by replacing the shortcode name and the specific parameters you require.
[myShortCodeName parameterOne=”bronze” parameterTwo=1]
Adding a shortcode programmatically (for developers)
If you need to add a shortcode outside of the page editor int he CMS you can do so in PHP inside of your custom templates or functions.