How to Use WordPress do_shortcode

1. Install and activate the plugin that contains the shortcode you want to use.

2. Find the shortcode you want to use. This can usually be found in the plugin’s documentation or by searching for it in the WordPress Codex.

3. Copy the shortcode and paste it into the WordPress editor.

4. Wrap the shortcode in the do_shortcode() function. This should look like this:

5. Save the changes and preview the page to see the shortcode in action.
[ad_1]

Extending site functionality is easy with the help of shortcodes. To place them on any part of your website, you can use the WordPress do_shortcode function. Here, we will show you how to apply it. So, let’s start by exploring the basics of WordPress shortcodes.

What Exactly is Shortcode?

Shortcode is a snippet of code, which allows you to execute a function like displaying content. For example, if you create a slider using the MetaSlider plugin, you need to embed the plugin’s shortcode into your site to show the slider.

However, you can only embed it on the site’s body or widget. Otherwise, the content won’t show up. To solve this problem, you can use WordPress do_shortcode function. It allows you to embed the shortcode anywhere you want – including the header. Here’s how it looks:

<?php echo do_shortcode( '[your shortcode goes here]' ); ?>

To apply this function, you need to access and tweak the theme files. Don’t forget to make a full website backup of your WordPress site and use the WordPress child theme beforehand to avoid data loss if something goes wrong.

How to Use WordPress do_shortcode?

Now, let’s try adding a shortcode using WordPress do_shortcode. For instance, let’s assume you want to include a slider in your theme’s header using MetaSlider – make sure you’ve installed the plugin. However, you don’t have any widget for the header area.

So, you need to embed the shortcode of the slider to the theme’s header file. To do so, use the following steps:

  1. Click on MetaSlider on the left sidebar of the WordPress admin dashboard.
  2. Copy the shortcode at the bottom right of the page.
    metaslider shortcode in wordpress dashboard

If you notice, the MetaSlider’s shortcode is already inside the WordPress do_shortcode function. You can then proceed with editing the theme’s header file by accessing your hosting provider’s file manager or an FTP client like FileZilla.

The following steps will show you how to edit theme files with Hostinger’s File manager – it can be applied in an FTP client as well:

  1. Access your hPanel and click on File Manager
  2. Go to the public_html folder and navigate to wp-contents -> themes.
  3. Find and access your currently active theme folder.
  4. Open header.php, then scroll down the page and put the do_shortcode function above the </header> tag.
    metaslider wordpress do_shortcode function in hostinger file manager
  5. Save and check how your website looks.
    result of wordpress do_shortcode function in display

Sometimes, editing theme core files can break your WordPress template. To solve it, you should alter the CSS to make your website look better. Check our tutorials on how to inspect elements with Chrome and download CSS cheatsheet.

Conclusion

Now you’ve learned how to use shortcodes and display them using the WordPress do_shortcode function. Just put it into the theme’s file, and you’re ready to go! Don’t forget to backup your site before editing the file to avoid the risk of losing data.

Do you have any questions regarding the topic? Drop a comment below!

[ad_2]

How to Use WordPress do_shortcode

WordPress do_shortcode is a powerful function that allows you to execute a shortcode in your WordPress theme or plugin. Shortcodes are small snippets of code that can be used to add dynamic content to your WordPress site. They are a great way to add functionality to your site without having to write a lot of code.

What is a Shortcode?

A shortcode is a small piece of code that can be used to add dynamic content to your WordPress site. Shortcodes are usually enclosed in square brackets, like this: [shortcode]. When a shortcode is used, it is replaced with the content that it is designed to display. For example, a shortcode might be used to display a list of recent posts, or a contact form.

How to Use do_shortcode

Using do_shortcode is easy. All you need to do is add the following code to your theme or plugin:

do_shortcode('[shortcode]');

Replace [shortcode] with the actual shortcode you want to execute. For example, if you wanted to display a list of recent posts, you would use the following code:

do_shortcode('[recent_posts]');

You can also pass parameters to the shortcode. For example, if you wanted to display a list of recent posts with a limit of 5, you would use the following code:

do_shortcode('[recent_posts limit="5"]');

Conclusion

WordPress do_shortcode is a powerful function that allows you to execute a shortcode in your WordPress theme or plugin. It is a great way to add dynamic content to your site without having to write a lot of code. With a few lines of code, you can easily add complex functionality to your site.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00