WordPress is a great platform when it comes to customizing things according to self. You can use multiple things at one time in WordPress. Shortcode is another feature of WordPress, which helps you simplify multiple tasks.

All you have to do is to create shortcodes and then use them at places where you want either multimedia files, forms, other relevant stuff. You can even paste the shortcode in the blogs, pages, product pages, etc.

What is ShortCode?

ShortCode is one of the best functions of WordPress. There are a lot of uses of ShortCode. Like, if you want to show any slide or a contact form, you don’t need to write the entire code again and again on separate posts/pages.

You can simply put the shortcode in the place where you want the slider or contact form or anything. It will embed everything in the place where you want.

ShortCode looks like a single-line code integrated into Square brackets.

[shortcode wp=”1”]

This is an example of a shortcode

What is do_shortcode

As you cannot use shortcodes everywhere, do_shortcode comes to tackle the situation. You can rely on PHP do_shortcode in order to use shortcodes everywhere on the website including header, footer, sidebar, and many other places.

do_shortcode helps you to make use of shortcodes on an extended range. You can use Shortcodes only with the help of WordPress Editor or page widgets but do_shortcode has a wide range.

<?php echo do_shortcode( ‘[shortcode wp=”1”]’ ); ?>

This is what the do_shortcode looks like. You will need to tweak some files to use the functionality of do_shortcode in WordPress.

How to Use do_shortcode in a WordPress Website

There are several steps included in using the do_shortcode in your WordPress website.

We should start the method with several important tasks which you should perform before proceeding. Follow this guide and make sure you are going on the right path.

Choose the Shortcode that you want

Now, its time to choose the shortcode that you want to add to your WordPress website. There are chances that you have already chosen the shortcode which you want to add as the do_shortcode. If this is the case, skip to the upcoming headline for the next step. Or We can help you choose any shortcode just to check the functionality of do_shortcode.

Also, There are various sliders, galleries, objects, icons & much more which are using shortcodes. It is easier and flexible for developers to write a single line code compared to writing the bigger HTML codes on WordPress editors. Just for the instance, We are going to use MetaSlider as our plugin to test the shortcodes on the WordPress website.

  1. Firstly, Open the WordPress dashboard.
  2. Click on Plugins>Add New Plugin.
  3. Search for MetaSlider from the search bar on top.
  4. Click on Install and then activate the plugin.
  5. Open the WordPress dashboard again and go to the settings of MetaSlider.
  6. Now add an image to the slider and save the changes.
  7. On the bottom-right, you will see a block for Shortcode. This is the exact shortcode that you need to know. Simply, copy the shortcode and note it down anywhere. We will have to use this shortcode on a header so as to check the functionality of do_shortcode.

But this is not as easy. Now comes the main task. You need to edit some files to make the use of do_shortcode on your WordPress website. But don’t worry, just follow the steps and you are good to go.

Edit Theme Files using cPanel or FTP

Now, you need to edit the theme files that we were telling you to do from the start. Now, we are going to locate the files which we want to edit first. You can use any of the methods you like to edit these files. We are going to use cPanel. You can even use FTP clients as well.

  • Firstly, Open the cPanel where your website is currently hosted.
  • Now, Click on the File Manager from the cPanel. This will open the file manager of your complete hosting. If you have multiple domains hosted on the same plan, look for the one where you wanted to use the shortcodes.
  • Navigate to the public_html folder in the file manager. And then visit the wpcontent folder from there.
  • Now, Click on the themes folder. It will show you the list of themes installed on your WordPress website.
  • Select the theme which you are currently using on your website. This should be the active theme of your website.
  • Once you are in the folder of your Active Theme, look for the header.php file. You can simply search for the header.php file from the search bar on top.
  • Right-Click on the header.php file and click on Edit to make changes in the header file.
  • Now, paste the do_shortcode at the end of the file or wherever you want to see the do_shortcode but before </header>. You need to make sure that the place is logical to have the shortcode.

<?php echo do_shortcode( ‘[shortcode wp=”1”]’ ); ?>

  • Imagine adding a long contact form in a menu, doesn’t seem to be practical right? Place the do_shortcode at the place where it can actually function without disturbing the user experience.
  • Once done, save the file and exit the file manager. Open the desired page and see if the do_shortcode actually worked for you. If you see any issue in the user experience, try to fix it with the hit & trial method.

One thing to note is – The do_shortcode which you have pasted in the active theme, will work only on the currently active theme. You will need to change it whenever you change the theme of your WordPress website. As the edits are made in the header.php file of a theme, which will not remain the same for other themes.

Let’s Conclude

This was all about How to use WordPress do_shortcode on your website. If you are having any doubts/queries, let us know through the comments. Also, If you have any other method which is easier than the above method for Using WordPress do_shortcode, share that with us. Follow us on Social Media platforms and share this article with your friends.

Have a Nice Day!!

Previous ArticleNext Article

Leave a Reply

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