How to Create Custom Shortcode in WordPress | A Step by Step guide.

How to Create 1

Today , we are going to create custom shortcode in WordPress. Basically, an effective technique to alter your posts and pages in WordPress is to develop shortcodes. However, you can find it difficult to use such a function on your site if you’re unfamiliar with the procedure.

We’ve created a guide to assist you in getting started because of this. Without the need of additional plugins, you can start modifying your content by looking at how shortcodes operate and how to use them effectively.

We’ll talk about WordPress shortcodes in this post and why you might use them. Then we’ll demonstrate how to create custom shortcode in WordPress. Let’s get going!

What Are WordPress Shortcodes?

WordPress shortcodes function as shortcuts that make it simple to swiftly embed components into a post or page. Typically, they are composed of one line of code enclosed in square brackets, such as [exampleshortcode], for reference. The front end of your website will show a preset feature thanks to this code.

Shortcodes were originally made available by WordPress with the Shortcode API’s introduction. This makes it simple for users to include interesting items on their posts and sites, like Facebook’s “Like” button or Google Maps.

WordPress comes with some standard shortcodes, some of them are:

  • caption: displays image galleries with captions wrapped around the content.
  • Audio: files can be embedded and played.
  • video: plays and embeds videos
  • playlist: a collection of music or video assets that can be viewed covers embedded objects

Some of the top WordPress plugins provide their own shortcodes. For example, WP Forms and Contact Form 7 both include shortcodes that make it simple to rapidly insert a WordPress contact form into a post or page. Additionally, you may add a WordPress button shortcode anywhere you want on your website by using a plugin like MaxButtons. 

download 2
download 3

What is Shortcode Api ?

The WordPress shortcode API is a simply collection of functions for adding shortcodes to posts and pages. For instance, including the following shortcode into a post’s or page’s body would add a photo gallery of the associated images:


Its time to create your Own Custom Shortcode in WordPress

Let’s learn how to install a WordPress shortcode to your own theme or plugin now that you know how shortcodes function. Of course, you will decide what your shortcode does. To get you started in this example, we’ll apply a basic function.

1.Write Shortcode Function:

First, you will open up your theme’s function.php file. Next, Now we will write a php code that we will use to create our own custom shortcode.

how to create custom shortcode in wordpress

You will echo the content that you want to display when you use your shortcode.

This php code has two parameters:

  1. $tag
  2. $Callback

Shortcode tag to be searched in post content. its usually the name of the shortcode.

The callback procedure or function is to execute after the shortcode has been located.
By default, each shortcode callback receives three parameters:

an array of attributes ($atts), the shortcode’s content ($content), or null if it is not set ($content), and finally the shortcode tag ($shortcode tag)
.Enter your shortcode:

Now just write your shortcode name in square brackets.The shortcode’s content will be displayed on your website’s page.The shortcode be written by using classic editor.

ztLkYBmsmLIjwR06N0P1bnnwoQSD9eoehR5W5X0JGRm8Ch11Wbln5RQ4nSB3h2tOe8WZGfWSZFVH346ndKgjMvryDh4xcx99tqVT81xMOb nK1GGtAfviw6sDxbwzjBQdbXwu2OuPhPjIoNCBd5hrQpvC

We at it doctorz, also created a video version of this article for you


Previously we learned how to fix maintance mode error in wordpress and today we learned how to create custom shortcodes in wordpress.

Shortcodes make it simple to add complex functionality to WordPress posts and pages. They are simple to create and improve your current project by adding dynamic functionality to simple content.

In this article, you have learnt how to create your own custom shortcode in just 2 simple steps.

  • Write a php function that executes custom shortcode
  • How to write and where to write your shortcode.

If you liked this article please make sure to follow us on social media and youtube.