◦ Comprehensive security
◦ 24/7 support
WordPress Guide → Build → do_shortcode
do_shortcode – What it means in WordPress & how to use it
Want to unlock extra features in WordPress without installing a dozen plugins? There’s a simple function that lets you insert advanced functionality wherever you need it—even inside template files. If you’re ready to tap into more of what WordPress shortcodes can do, you’ll want to get familiar with this hidden gem.
Get fast, reliable hosting for WordPress
Power your site with the industry’s fastest, most optimized WordPress hosting
What is the do_shortcode?
do_shortcode is a WordPress PHP function that lets you run a shortcode directly in your theme files, plugins, or anywhere PHP is allowed. Normally, shortcodes are used inside post or page content. But with do_shortcode, you can call those same shortcodes outside of the content editor—like in sidebars, custom page templates, or even headers and footers.
This is especially helpful when you’re building a custom theme or plugin and want to use a shortcode without manually inserting it into a post or widget. Instead of relying on the block editor or Classic Editor, you can run the shortcode programmatically.
How the do_shortcode works
Using do_shortcode is straightforward. Here’s how to do it:
- Understand the function. The syntax is:
echo do_shortcode(‘[shortcode]’);
It takes a string (the actual shortcode, wrapped in square brackets) and returns the rendered output. - Insert it into your PHP file. Place the function where you want the shortcode output to appear. For example, if you’re editing your page.php template and want to include a contact form, you’d use:
echo do_shortcode(‘[contact-form-7 id=”123″]’); - Test the output. Load the page where you placed the function and make sure the content appears as expected. If the shortcode is from a plugin like Contact Form 7, the plugin must be active.
- Escape output if needed. In rare cases where output might include user-generated content, consider sanitizing it using wp_kses_post() or similar.
Troubleshooting do_shortcode
If do_shortcode isn’t working as expected, check the following:
- Check the shortcode syntax. Make sure the shortcode is wrapped in single or double quotes and includes the correct parameters.
- Confirm the shortcode is registered. If the shortcode comes from a plugin or custom function, make sure it’s loaded before you call do_shortcode. Use hooks like init to register shortcodes.
- Look out for quote conflicts. Using single quotes inside single-quoted strings can break your code. Escape them properly or switch to double quotes on the outside.
- Debug plugin conflicts. Disable other plugins temporarily to check if one is interfering with the shortcode. Some shortcodes depend on specific scripts or styles being enqueued.
- Check PHP errors. Enable WP_DEBUG in your wp-config.php file to see if there are any function errors or typos.
Upgrade your WordPress experience
With do_shortcode, you’re no longer limited to adding shortcodes in the post editor. You can drop dynamic features anywhere in your theme and make your site more flexible.
Ready to use it? Try adding a shortcode to your header.php or footer.php to see the power in action.
When you’re ready to really take the training wheels off, consider upgrading your hosting for WordPress. Professional hosting improves speeds, security, and reliability for a website and a brand that people find engaging and trustworthy. Liquid Web’s WordPress hosting options configure business-class servers and support plans specifically for WordPress websites.
Don’t want to deal with server management and maintenance? Our fully managed hosting for WordPress is the best in the industry. Our team are not only server IT experts, but WordPress hosting experts as well. Your server couldn’t be in better hands.
Click through below to explore all of our hosting for WordPress options, or chat with a WordPress expert right now to get answers and advice.
Additional resources
How to build a WordPress site →
A complete beginner’s guide that covers 9 key steps to a successful launch
WordPress Slug: What is it and what should you do with it? →
Learn how to create and customize WordPress slugs for better SEO and user-friendly URLs.
How to use WordPress Gutenberg blocks →
A complete beginner’s guide to Gutenberg blocks