How to Add A Shortcode in WordPress Website?

Many plugin allows us to add some special content and additional functionality to your post or page. User likes to see a simple list of popular posts not a complex forms. At some stage user want to apply widget or any content which they saw in other site( it can be page, post and sidebar widget ) in WordPress template file.

But luckily WordPress is having the extra plugins for these type of requirement of users called a shortcode for doing these extra things easily. This blog will give you the procedure of installing, building and uses a shortcode at the time of installation of WordPress.

What is WordPress Shortcode

First Shortcode was released in WordPress 2.5. Now shortcode is used by the lot’s of WordPress plugins for getting easy to user for applying these content to there pages and post. The Shortcode API allow us to create our own shortcodes by adding the features to your theme functions.php template.

In depth, we can say shortcode is a special tag that we can apply in our post. And our post will exchanged by different content from previous content on our website. As we know that, we already have the built in shortcode in our WordPress gallery on our page. A Shortcode will looks same as an HTML tag, but it is surrounded with square brackets. When this page will actually loaded on browser, it seems different because the code is exchanged by other code. A very best thing about WordPress is that we can create our own Shortcode like audio, caption, embed, gallery and video.That makes it much more pretty.

How do I create WordPress Shortcode

When we open our page of blog with shortcode, WordPress will exchange the entire actual code with extra theme. Even, WordPress makes it easy to create our own shortcodes. So, the first thing to create a function that gives actual outputs of Adsense code. Entire code will send to the functions.php in your theme( may be it is plugin file). And the function is:


function get_adsense($atts) {

return ‘<script type=”text/javascript”><!–

google_ad_client = “pub-546321545321589”;

/* 468×60, created 9/13/10 */

google_ad_slot = “54321565498”;

google_ad_width = 468;

google_ad_height = 60;



<script type=”text/javascript”






It will returns my Google Adsense code as a string. Now there is also we have function doing whatever we want. Here WordPress will comes in. Now it’s time to set up the adsense Shortcode.

add_shortcode(‘adsense’, ‘get_adsense’)

Here, the first parameter is the name of shortcode, and when new shortcode is come into then the second parameter will be appointed. Result of ’Get_adsense’ method exchange [adsense].

Things to remember about Shortcode

When not to use Shortcodes: Every time uses of shortcode is not good for our site. If you will use lot’s shortcode in every post then you are going to grab by it. There are maximum themes having up to 200+ shortcode. So, if you will use the shortcode in every post, then always you had to use that themes which not possible. If you want to create these shortcode themes at the action of click button, then you should have the knowledge about that how we will add CSS buttons in WordPress.

Future Proof Your Shortcodes: If you want to excessively use your theme then it is not good for you. Because your every shortcode not have the same code so, here changing in every theme is very difficult task. Although, it is good to add specific plugin. Normally, copy and paste the shortcode in your functions.php file of theme and then paste it into your plugin.

How to search for Shortcode in your WordPress Theme:

Above we discussed about future proof your shortcode, for that you should know that what is the shortcode function, and how it looks like and how it can be find. First of all, open that folder which is having your theme that is found in /wp-content/themes/your-theme-name/. You can look inside of that folder for the function.php file or if the theme has an includes folder, then inside there.

Open and search the term add_shortcode into the files. We are giving you an example how a shortcode piece looks like:

function my_shortcode_function() {

$i = ‘<p>Hello World!</p>’;

return $i;


add_shortcode(‘my-shortcode’, ‘my_shortcode_function’);



These lines of codes creates a shortcode ‘my-shortcode’, it will return those text whatever we want to replace into a WordPress page like ‘my-shortcode’.

Using Shortcodes in Widgets: 

There is no restriction or limitation to apply lot’s of shortcodes on our posts and pages. For that you will use it under the WordPress text widgets. Normally put that text widget to sidebar and then add shortcode into it. Note that, this is not activated before you done this. If you are not able to see your shortcode in a widget then you require to add this code in your theme’s functions.php file or a site-specific plugin.

add_filter(‘widget_text’, ‘do_shortcode’);

Add Shortcode in Theme Files: Here you require to find the output of shortcode into your theme inside area which is not belong to widget. Then use your shortcodes there. For including those shortcode, write the following code

<?php echo do_shortcode(“[example_shortcode]”); ?>

Hiding a Broken Shortcode: Usually users don’t think that their shortcodes will always not work. Sometimes, after few months if user will go to their earliest shortcode for searching any text. So finally, you have two way to solve it. Either manually you can delete the shortcode from every post, or disable the shortcode. Add this code to your theme’s functions.php file.

add_shortcode( ‘shortcodetag’, ‘__return_false’ );

We hope that this article helped you to add a shortcode in WordPress Website. In addition to this keep an eye on this blog and our our WordPress


Leave a Reply

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