{"id":2622,"date":"2025-08-22T11:15:31","date_gmt":"2025-08-22T11:15:31","guid":{"rendered":"https:\/\/hostrago.com\/knowledge-base\/?p=2622"},"modified":"2025-08-22T11:15:33","modified_gmt":"2025-08-22T11:15:33","slug":"steps-to-use-wordpress-do-shortcode","status":"publish","type":"post","link":"https:\/\/hostrago.com\/knowledge-base\/steps-to-use-wordpress-do-shortcode\/","title":{"rendered":"Discover the Steps To Use WordPress do_shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you have been working with WordPress for a while, you\u2019ve probably come across <strong>shortcodes<\/strong>. They are small pieces of code wrapped in brackets, like <code>[shortcode]<\/code>, that help you add dynamic content to your pages and posts. But sometimes, you may want to insert these shortcodes directly into your theme files, widgets, or custom PHP code. This is where you need to <strong>use WordPress do_shortcode<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The function <strong>do_shortcode<\/strong> is a built-in WordPress function that allows you to execute shortcodes anywhere within your website, beyond just the content editor. If you want more flexibility and complete control over your site, learning how to <strong>use WordPress do_shortcode<\/strong> will save you time and give you customization power.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we\u2019ll break down everything you need to know: what do_shortcode is, where you can use it, and the exact steps to implement it correctly. By the end, you\u2019ll have a clear idea of how to enhance your WordPress site with custom shortcodes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is do_shortcode in WordPress?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/wordpress.org\/\" target=\"_blank\" rel=\"noopener\">WordPress <\/a>shortcodes are like shortcuts that allow you to add features without writing lengthy code. For example, <code><div class=\"epcl-gallery\"><ul class=\"columns-3 grid-container grid-parent np-tablet np-mobile\">\r\n                        <li class=\"grid-33 tablet-grid-33 mobile-grid-50\">\r\n                           <div class=\"wrapper\">\r\n                               <a href=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/08\/Discover-the-Steps-to-Use-WordPress-do_shortcode-1024x576.webp\" class=\"full-image mfp-image hover-effect\" title=\"\"><span class=\"img cover\" style=\"background: url(https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/08\/Discover-the-Steps-to-Use-WordPress-do_shortcode-300x169.webp);\"><\/span><\/a>\r\n                           <\/div>\r\n                        <\/li><\/ul><div class=\"clear\"><\/div><\/div><\/code> can insert an image gallery instantly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, WordPress processes shortcodes inside posts and pages. But what if you want the shortcode to run in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Theme templates<\/li>\n\n\n\n<li>Sidebar widgets<\/li>\n\n\n\n<li>Custom PHP code<\/li>\n\n\n\n<li>Gutenberg block editor (in certain conditions)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s when you need <code>do_shortcode<\/code>. It acts like a bridge that tells WordPress, \u201cHey, please execute this shortcode here.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The general syntax looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-php\"><code>&lt;?php echo do_shortcode('&#091;shortcode]'); ?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Where Can You Use WordPress do_shortcode?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can use <code>do_shortcode<\/code> in different parts of your WordPress setup:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Theme Files<\/strong><br>Add shortcodes directly inside template files like <code>header.php<\/code>, <code>footer.php<\/code>, or <code>single.php<\/code>. <code>&lt;?php echo do_shortcode('<p class=\"wpcf7-contact-form-not-found\"><strong>Error:<\/strong> Contact form not found.<\/p>'); ?><\/code><\/li>\n\n\n\n<li><strong>Widgets<\/strong><br>WordPress widgets don\u2019t always support shortcodes. By using <code>do_shortcode<\/code>, you can execute them in text widgets. <code>&lt;?php echo do_shortcode('[recent-posts]'); ?><\/code><\/li>\n\n\n\n<li><strong>Custom PHP Code<\/strong><br>If you\u2019re building a custom plugin or functionality, <code>do_shortcode<\/code> allows you to include WordPress shortcodes inside your logic.<\/li>\n\n\n\n<li><strong>Page Builders &amp; Custom Templates<\/strong><br>Some themes or builders may restrict shortcode placement. <code>do_shortcode<\/code> bypasses this and ensures your shortcode runs.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step: How to Use WordPress do_shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s walk through the exact steps with an example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Identify Your Shortcode<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you\u2019re using Contact Form 7. The shortcode may look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-php\"><code>&#091;contact-form-7 id=\"1234\" title=\"Contact Us\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Insert in PHP Template<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open your theme\u2019s template file (for example, <code>page.php<\/code> or <code>single.php<\/code>) and paste the shortcode with do_shortcode:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-php\"><code>&lt;?php echo do_shortcode('&#091;contact-form-7 id=\"1234\" title=\"Contact Us\"]'); ?&gt;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Save and Test<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Save your file, reload your page, and the shortcode should execute where you placed it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Use Cases<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Adding a Contact Form in Header or Footer:<\/strong><br>Useful if you want a form to appear sitewide.<\/li>\n\n\n\n<li><strong>Inserting Sliders:<\/strong><br>Most slider plugins provide shortcodes. With <code>do_shortcode<\/code>, you can place them in any template area.<\/li>\n\n\n\n<li><strong>Displaying Recent Posts:<\/strong><br>Shortcodes for post lists can be inserted into sidebars or custom layouts.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes When Using do_shortcode<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting <code>echo<\/code> before <code>do_shortcode<\/code>. Without it, nothing will display.<\/li>\n\n\n\n<li>Placing the code inside functions without properly returning the output.<\/li>\n\n\n\n<li>Using it in the wrong template file where WordPress cannot process the shortcode.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use WordPress do_shortcode Instead of Default Shortcodes?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using the default shortcode <code>[shortcode]<\/code> inside posts works fine, but <code>do_shortcode<\/code> expands possibilities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It lets developers integrate plugin features deeply into themes.<\/li>\n\n\n\n<li>It improves user experience by placing dynamic content in unexpected areas.<\/li>\n\n\n\n<li>It gives full customization power over design and layout.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For hosting providers like <strong><a href=\"https:\/\/hostrago.com\/\">Hostrago<\/a><\/strong>, if you want to add pricing tables or promotional banners sitewide, <code>do_shortcode<\/code> is an efficient method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Learning how to <strong>use WordPress do_shortcode<\/strong> is an essential skill for developers and site owners who want more control over WordPress functionality. Whether you\u2019re adding forms, sliders, galleries, or custom plugin features, <code>do_shortcode<\/code> ensures your shortcodes run smoothly anywhere on your site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re running a WordPress site, you\u2019ll also need reliable hosting for smooth performance. At <strong><a href=\"https:\/\/hostrago.com\/\">Hostrago<\/a><\/strong>, we offer affordable and high-speed <a href=\"https:\/\/hostrago.com\/wordpress-hosting\/\">WordPress hosting<\/a> plans that make managing and customizing your site effortless.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have been working with WordPress for a while, you\u2019ve probably come across shortcodes. They are small pieces of code wrapped in brackets, like&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2625,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[857,860,858,859],"class_list":["post-2622","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-use-wordpress-do_shortcode","tag-wordpress-customization","tag-wordpress-do_shortcode","tag-wordpress-shortcodes"],"menu_order":0,"_links":{"self":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=2622"}],"version-history":[{"count":3,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2622\/revisions"}],"predecessor-version":[{"id":2626,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2622\/revisions\/2626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media\/2625"}],"wp:attachment":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=2622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=2622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=2622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}