UXDE dot Net

How to Add a Shortcode in WordPress – 3 Different Ways

If you want to add a shortcode in WordPress, then you need to know how to do it. But you don’t know how to get it done, right?

Shortcodes are a great way to customize your website without having to write code. Many WordPress plugins and themes use shortcodes to add specialized content like contact forms, image galleries, sliders, and more.

In this article, we’ll cover the basics of adding a shortcode in WordPress with very little effort. So, let’s dive deep into the article.

How to Add a Shortcode in WordPress

What are Shortcodes?

Shortcodes are a feature of WordPress that allows you to easily insert content into a post or page. A shortcode is simply a block of code that you insert into a post or page, and WordPress will automatically create the necessary HTML and CSS for you. Moreover, they are code shortcuts, allowing you to add dynamic content to WordPress posts, pages, and sidebar widgets. They are enclosed with square brackets, for example: [ourshortcode]

To better understand shortcodes, let’s take a look at the background of why they were added in the first place.

WordPress filters all content to make sure that no one uses posts and page content to insert malicious code into the database. This means that you can write basic HTML in your posts, but you cannot write PHP code.

But what if you wanted to run some custom code inside your posts to display related posts, banner ads, contact forms, galleries, etc.?

This is where Sortcode API comes into play.

Basically, it allows developers to add their code inside a function and then register that function as a shortcode, so users can easily use it without having any coding knowledge. When WordPress finds the shortcode, it will automatically run the code associated with it.

Let’s see how to easily add shortcodes to your WordPress posts and pages.

How to Add a Shortcode in WordPress Posts and Pages

First, you need to edit the post and page where you want to add the shortcode.

After, that you need to click on the add block button to insert a shortcode block.

How to Add a Shortcode in WordPress- Add a shortcode in WordPress

After adding the shortcode block, you can simply enter your shortcode in the block settings. The shortcode will be provided by various WordPress plugins that you might be using such as WPForms for contact forms, OptinMonster for email marketing forms, and WP Call Button for inserting a click-to-call button, etc.

How to Add a Shortcode in WordPress Sidebar Widgets

You can also use shortcodes in WordPress sidebar widgets. To do that, simply visit the Appearance>> Widgets pages and add a ‘Shortcode’ widget block to a sidebar. Now you can paste your shortcode inside the text area of the widget.

Don’t forget to click on the ‘Update’ button to store your widget settings. After that, you can visit your WordPress website to see the live preview of the shortcode in the sidebar widget.

How to Add a Shortcode in Old WordPress Classic Editor

If you are still using the old classic editor in WordPress, then here is how you can add shortcodes to your WordPress posts and pages.

Simply edit the post and page where you want to add the shortcode. You can paste the shortcode anywhere inside the content editor where you want it to be displayed. Just make sure the shortcode is in its own line.

Don’t forget to save your changes. After that, you can preview your post and page to see the shortcode in action.

Conclusion

We hope this article helped you learn how to add a shortcode in WordPress. If you follow the steps we mentioned in our article above, we believe you will surely learn how to add a shortcode in WordPress website with the utmost possible ease.

Post Tags:

Posted by on

Leave a Reply

Your email address will not be published. Required fields are marked *