Adding dynamic content in your WordPress posts/pages is very easy if you consider to add a shortcode. All you have to do is place code inside your page/post, and your dynamic content will be ready. There are many themes and plugins in WordPress that use shortcodes to add galleries, sliders, contact forms, and more.
Using WordPress shortcode is very easy, in this post I will show you how to add your own shortcode in WordPress. But before add a shortcode, it is essential to know about shortcode WordPress.
What is ShortCode in WordPress?
In short, shortcodes are more like code shortcuts. The shortcode is used to save time on repeated work. WordPress Shortcodes help you to add dynamic content to WordPress pages, posts, widgets, etc. Shortcodes are written inside square brackets like
[shortcode]
WordPress filters all contents of your pages and posts, then make sure so that no one can insert any malicious code in the database. That means you cannot write any PHP code except basic HTML in your posts/pages.
What if you want to run some custom codes inside your post to display ads, contact forms, galleries, related posts, etc.?
Well, for this reason, shortcodes are born. Shortcode allows developers to add their desired code in a function and then register it with WordPress as a shortcode. Therefore, users can easily use it without having any prior coding knowledge.
When WordPress finds any shortcode, it automatically runs the code associated with it.
Now, let’s check out how to add a shortcode in WordPress.
Add a Shortcode in WordPress Post/Page
To add a shortcode to your WordPress post/page, you need to have a plugin that works with shortcodes. There are a lot of plugins that work with shortcodes, like WP Table Builder, Contact Form 7, WP Call button, OptinMonster, etc.
After you install any plugin that will provide you with a shortcode, copy the code.
Step #1: Add a Shortcode Block
Create a new post/page or edit the existing one, in which you want to add a shortcode. Now click on the add block (+) button and insert a shortcode block.
Type ‘shortcode’ in the search bar and the shortcode block will appear.
Step #2: Paste The Shortcode
After adding the shortcode block, paste the shortcode in the block.
Now save the post/page and preview the changes that shortcode has brought.
Add Shortcode in WordPress Widget
Shortcodes also work great with WordPress widgets. To add a shortcode in WordPress widget, go to Appearance -> Widgets page.
Now click on the add block or plus icon from the below. Search for “shortcode” block and insert it by clicking on it.
Paste your shortcode and click the ‘Update’ button from the top left.
Now visit your WordPress site and check the changes live.
Final Words
I hope you have learned how to add a shortcode in WordPress with the help of this post. If you like this post, please consider sharing the post. Don’t forget to share your thoughts, and I will be happy to reply to you.
Leave a Reply