cPanel

Discover the Steps To Use WordPress do_shortcode

Discover the Steps To Use WordPress do_shortcode WordPress is well-known for its flexibility and ease of customization. One of the features that makes WordPress so powerful is its shortcode functionality. Shortcodes allow users to…

Discover the Steps To Use WordPress do_shortcode

WordPress is well-known for its flexibility and ease of customization. One of the features that makes WordPress so powerful is its shortcode functionality. Shortcodes allow users to insert dynamic content such as contact forms, image sliders, galleries, tables, and other plugin-generated elements without writing complex code. However, by default, shortcodes only work within posts, pages, and widget areas.

There are situations where website owners want to display shortcode-generated content in other locations, such as the website header, footer, sidebar, or custom theme templates. In such cases, the WordPress do_shortcode() function becomes extremely useful. This function enables WordPress to process and display shortcodes directly from PHP files, allowing you to place dynamic content virtually anywhere on your website.

In this guide, you will learn how to Use WordPress do_shortcode with a plugin, understand its benefits, and discover best practices for implementing it safely.

What is the WordPress do_shortcode() Function?

The do_shortcode() function is a built-in WordPress function that executes a shortcode and displays its output. Instead of placing a shortcode inside a page or post, you can insert it directly into a theme file using PHP.

For example:

<?php echo do_shortcode('[metaslider id="123"]'); ?>

When WordPress encounters this code, it processes the shortcode and displays the resulting content, such as a slider, form, or gallery.

Many developers Use WordPress do_shortcode when they need to display plugin-generated content in areas where shortcodes are not supported by default.

Prerequisites

Before proceeding, ensure that:

  • You have access to your hosting control panel.
  • You have a complete backup of your WordPress website.
  • You know the shortcode you want to display.
  • A child theme is being used to prevent changes from being overwritten during theme updates.
  • The plugin generating the shortcode is installed and activated.

Using a child theme is highly recommended because theme updates can overwrite modifications made directly to theme files.

Steps to Use WordPress do_shortcode with a Plugin

In this example, we will use the MetaSlider plugin to display a slider in the website header using the WordPress do_shortcode() function.

Step 1: Log in to Your WordPress Dashboard

Begin by accessing your WordPress administration area.

Open your web browser and visit:

https://yourdomain.com/wp-admin

Enter your administrator username and password, then click Log In.

Once logged in, you will be redirected to the WordPress Dashboard.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Step 2: Install and Activate MetaSlider

First, install the plugin that generates the shortcode.

  1. Navigate to Plugins → Add New.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

2. Search for MetaSlider.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

3. Click Install Now.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

4. Once installation is complete, click Activate.

 

discover-the-steps-to-use-wordpress-do_shortcode

After activation, the MetaSlider menu will appear in the WordPress dashboard.

Step 2: Create a Slider

Next, create the slider that you want to display.

  1. Click Gallery from the left-hand menu then Click Galleries.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

2. Select Add New Gallery.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

3. Upload the images you want to include.

4. Configure the slider settings according to your requirements.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

5. Save the slider.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Once saved, MetaSlider automatically generates a shortcode for the slider.

Step 3: Copy the Slider Shortcode

After saving the slider:

  1. Locate the shortcode displayed within the MetaSlider interface.
  2. Copy the shortcode.

Example:

[metaslider id="123"]

You will need this shortcode when adding the do_shortcode() function to your theme file.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Step 4: Access Your Website Files

Now you need to edit the appropriate theme file.

  1. Log in to your hosting control panel.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

2. Go to Files then File Manager.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

3. Navigate to:

 

  • public_html/

 

discover-the-steps-to-use-wordpress-do_shortcode

 

  • wp-content/

 

discover-the-steps-to-use-wordpress-do_shortcode

 

  • themes/

 

discover-the-steps-to-use-wordpress-do_shortcode

 

  1. Open the folder for your currently active theme.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Step 5: Edit the Header File

To display the slider in the website header:

  1. Locate the header.php file.
  2. Click Edit.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

3. Again Click Edit.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Depending on your design, this could be below the navigation menu or above the page content.

Step 6: Add the do_shortcode() Function

Insert the following code:

<?php echo do_shortcode('[metaslider id="123"]'); ?>

Replace the shortcode with the one copied from your MetaSlider plugin if it differs.

This tells WordPress to process the shortcode and display the slider output at that location.

Many developers regularly Use WordPress do_shortcode in theme files because it allows plugin content to be displayed exactly where needed.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Step 7: Save the Changes

After adding the code:

  1. Save the header.php file.
  2. Clear any caching plugins.
  3. Refresh your website.

Your changes should now be active.

 

discover-the-steps-to-use-wordpress-do_shortcode

 

Step 8: Verify the Slider Display

Finally:

  1. Visit your website.
  2. Check the header area.
  3. Confirm that the slider is displaying correctly.

If the shortcode appears as plain text instead of a slider, verify that the plugin is active and the code has been entered correctly.

Why Use WordPress do_shortcode?

There are several reasons why website owners choose to Use WordPress do_shortcode:

  • Display content in headers and footers.
  • Show sliders above page content.
  • Add contact forms to custom template files.
  • Insert promotional banners in specific locations.
  • Display plugin-generated content in sidebars.
  • Improve theme customization flexibility.
  • Create dynamic website layouts without extensive coding.

The function offers a simple and effective way to integrate plugin features directly into your WordPress theme.

Benefits of Using WordPress do_shortcode

Using the WordPress do_shortcode() function offers several advantages for website owners and developers:

  • Display Content Anywhere
  • Enhanced Website Customization
  • Easy Plugin Integration
  • Improved User Experience
  • Reduces Development Time
  • Flexible Theme Design

Conclusion

The WordPress do_shortcode() function is a powerful tool for displaying shortcode-generated content outside traditional content areas. Whether you want to add a MetaSlider slider to your header, display a contact form in a custom template, or integrate plugin features into your theme design, this function makes the process simple and efficient. By following the steps outlined above, you can confidently Use WordPress do_shortcode to place dynamic content exactly where it is needed. With proper planning, backups, and the use of a child theme, you can safely enhance your website’s functionality while maintaining complete control over its layout and design.

Originally published on WebyStrata.com Blog.

Written By

Shaik Sai Meera

WebyStrata Editorial Team

Shaik Sai Meera shares practical publishing insights, comparisons, and WordPress-focused growth guidance for modern web teams.

420 articles published Member since 2021