Quick Guide for Adding a Shortcode in WordPress

Quick Guide for Adding a Shortcode in WordPress

Do you want to add a shortcode in WordPress? If yes then this post is for you. Shortcodes offer an easy way for you to add dynamic content into WordPress pages, posts and sidebars. Most WordPress themes and plugins use shortcodes to add specialized content such as contact forms, sliders and image galleries. In this post we will be looking at how you can create your own shortcode.

What are shortcodes?

In WordPress shortcodes are shortcodes that help you to add dynamic content in your pages, posts and sidebar widgets. When you add a shortcode in WordPress it will be displayed in a square bracket like this:

[myshortcode]

WordPress filters all the content to ensure pages and posts are not used to insert malicious code in the database. This means you can easily add HTML in your page or posts but cannot add PHP code. But what happens if you want to run custom code in the post to display banner ads, related posts, galleries or contact forms? This is where you use Shortcode API. This allows you to add your code in the function and register the function with WordPress as shortcode. Users can then use the feature without having any coding knowledge.

How to add shortcode in WordPress page or post

To add shortcode in WordPress you need to edit your target page or post. Click on add block button and then insert the shortcode block. You can then add the shortcode in the block settings. The shortcode can be provided by any of the WordPress plugins you are using such as WPForms for the contact forms WP call button for adding Click to Call button or OptinMonster for the email marketing forms.

Adding shortcode in WordPress sidebar widgets

To do this you need to go to Appearance>>Widgets page and then select the ‘Text’ widget to the sidebar. After that you can paste your shortcode into the text area of your widget. Save the changes for the shortcode to be added. You can then visit your website and preview the shortcode in your sidebar widget.

Adding shortcode in the old WordPress classic editor

If you haven’t upgraded to the new editor, you can still add a shortcode to your page or post. You need first to edit the page or post you want to add the shortcode then paste the shortcode where you want it to be displayed in the page. You must ensure the shortcode is in its own line.

Add a shortcode in WordPress