{"id":4521,"date":"2019-11-15T02:32:35","date_gmt":"2019-11-15T02:32:35","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=4521"},"modified":"2026-03-10T10:07:10","modified_gmt":"2026-03-10T10:07:10","slug":"wordpress-do_shortcode","status":"publish","type":"post","link":"\/my\/tutorials\/wordpress-do_shortcode","title":{"rendered":"How to use WordPress do_shortcode"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Extending site functionality is easy with the help of shortcodes. To place them on any part of your website, you can use the WordPress <strong>do_shortcode<\/strong> function. Here, we will show you how to apply it. So, let&rsquo;s start by exploring the basics of WordPress shortcodes.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\" target=\"_blank\" rel=\"noopener\">Download all in one WordPress cheat sheet<\/a><\/p><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-exactly-is-shortcode\">What Exactly is Shortcode?<\/h2><p>Shortcode is a snippet of code, which allows you to execute a function like <strong>displaying content<\/strong>. For example, if you create a slider using the <a href=\"https:\/\/wordpress.org\/plugins\/ml-slider\/\" target=\"_blank\" rel=\"noreferrer noopener\">MetaSlider<\/a> plugin, you need to embed the plugin&rsquo;s shortcode into your site to show the slider.<\/p><p>However, you can only embed it on the site&rsquo;s <strong>body<\/strong> or <strong>widget<\/strong>. Otherwise, the content won&rsquo;t show up. To solve this problem, you can use WordPress <strong>do_shortcode<\/strong> function. It allows you to embed the shortcode anywhere you want &ndash; including the header. Here&rsquo;s how it looks:<\/p><pre class=\"wp-block-preformatted\">&lt;?php echo do_shortcode( '[your shortcode goes here]' ); ?&gt;<\/pre><p>To apply this function, you need to access and tweak the <strong>theme files<\/strong>. Don&rsquo;t forget to <a href=\"\/my\/tutorials\/backup-wordpress\">make a full website backup of your WordPress site<\/a> and use the <a href=\"\/my\/tutorials\/how-to-create-wordpress-child-theme\">WordPress child theme<\/a> beforehand to avoid data loss if something goes wrong.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-use-wordpress-do-shortcode\">How to Use WordPress do_shortcode?<\/h2><p>Now, let&rsquo;s try adding a shortcode using WordPress <strong>do_shortcode<\/strong>. For instance, let&rsquo;s assume you want to include a <strong>slider<\/strong> in your theme&rsquo;s <strong>header <\/strong>using MetaSlider &ndash; make sure you&rsquo;ve <a href=\"\/my\/tutorials\/wordpress\/how-to-install-wordpress-plugins\">installed the plugin<\/a>. However, you don&rsquo;t have any widget for the header area.<\/p><p>So, you need to embed the shortcode of the slider to the <strong>theme&rsquo;s header file<\/strong>. To do so, use the following steps:<\/p><ol class=\"wp-block-list\">\n<li>Click on <strong>MetaSlider <\/strong>on the left sidebar of the <a href=\"\/my\/tutorials\/wordpress\/how-to-login-to-wordpress-dashboard\">WordPress admin dashboard<\/a>.<\/li>\n\n\n\n<li><strong>Copy<\/strong> the shortcode at the bottom right of the page.<br><img decoding=\"async\" width=\"1873\" height=\"888\" class=\"aligncenter size-full wp-image-22416\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/metaslider-shortcode-in-wordpress-dashboard.png\" alt=\"metaslider shortcode in wordpress dashboard\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-shortcode-in-wordpress-dashboard.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-shortcode-in-wordpress-dashboard-150x71.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-shortcode-in-wordpress-dashboard-300x142.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-shortcode-in-wordpress-dashboard-768x364.png 768w\" sizes=\"(max-width: 1873px) 100vw, 1873px\" \/><\/li>\n<\/ol><p>If you notice, the MetaSlider&rsquo;s shortcode is already inside the WordPress <strong>do_shortcode<\/strong> function. You can then proceed with editing the theme&rsquo;s <strong>header<\/strong> file by accessing your hosting provider&rsquo;s <strong>file manager<\/strong> or an <a href=\"\/my\/tutorials\/ftp\/filezilla-ftp-configuration\"><strong>FTP client <\/strong><\/a>like <a href=\"https:\/\/filezilla-project.org\" target=\"_blank\" rel=\"noreferrer noopener\">FileZilla<\/a>.<\/p><p>The following steps will show you how to edit theme files with Hostinger&rsquo;s File manager &ndash; it can be applied in an <strong>FTP client<\/strong> as well:<\/p><ol class=\"wp-block-list\">\n<li>Access your <strong>hPanel<\/strong> and click on <strong>File Manager<\/strong><\/li>\n\n\n\n<li>Go to the <strong>public_html <\/strong>folder&nbsp;and navigate to <strong>wp-contents -&gt; themes<\/strong><strong>.<\/strong><\/li>\n\n\n\n<li>Find and access your <strong>currently<\/strong> <strong>active theme<\/strong> folder.<\/li>\n\n\n\n<li>Open <strong>header.php<\/strong>, then scroll down the page and put the <strong>do_shortcode&nbsp;<\/strong>function above the <strong>&lt;\/header&gt; <\/strong>tag.<br><img decoding=\"async\" class=\"aligncenter wp-image-22418 size-full\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager.png\" alt=\"metaslider wordpress do_shortcode function in hostinger file manager\" width=\"1391\" height=\"735\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager.png 1391w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager-150x79.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager-300x159.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager-768x406.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/metaslider-wordpress-do-shortcode-function-in-hostinger-file-manager-1024x541.png 1024w\" sizes=\"(max-width: 1391px) 100vw, 1391px\" \/><\/li>\n\n\n\n<li><strong>Save<\/strong>&nbsp;and check how your website looks.<br><img decoding=\"async\" class=\"aligncenter wp-image-22419 size-full\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/06\/result-of-wordpress-do-shortcode-function-in-display.png\" alt=\"result of wordpress do_shortcode function in display\" width=\"1024\" height=\"497\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/result-of-wordpress-do-shortcode-function-in-display.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/result-of-wordpress-do-shortcode-function-in-display-150x73.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/result-of-wordpress-do-shortcode-function-in-display-300x145.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2017\/06\/result-of-wordpress-do-shortcode-function-in-display-768x372.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/li>\n<\/ol><p>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 <a href=\"\/my\/tutorials\/website\/how-to-inspect-and-change-style-using-google-chrome\">inspect elements<\/a> with Chrome and <a href=\"\/my\/tutorials\/css-cheat-sheet\">download CSS cheatsheet<\/a>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/my\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner-1024x300.png\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-1024x300.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-768x225.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner-1536x450.png 1536w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h2><p>Now you&rsquo;ve learned how to use shortcodes and display them using the WordPress <strong>do_shortcode&nbsp;<\/strong>function. Just put it into the theme&rsquo;s file, and you&rsquo;re ready to go! Don&rsquo;t forget to backup your site before editing the file to avoid the risk of losing data.<\/p><p>Do you have any questions regarding the topic? Drop a comment below!<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Discover More Expert WordPress Techniques<\/h4>\n                    <p><a href=\"\/my\/tutorials\/activate-wordpress-multisite\">WordPress Multisite<\/a><br>\n<a href=\"\/my\/tutorials\/wordpress-custom-post-types\">Custom Post Types in WordPress<\/a><br>\n<a href=\"\/my\/tutorials\/wordpress-custom-css\">Add Custom CSS to WordPress<\/a><br>\n<a href=\"\/my\/tutorials\/edit-html-wordpress\">How to Edit HTML in WordPress<\/a><br>\n<a href=\"\/my\/tutorials\/headless-wordpress\">Headless WordPress<\/a><br>\n<a href=\"\/my\/tutorials\/wordpress-rest-api\">WordPress Rest API<\/a><br>\n<a href=\"\/my\/tutorials\/how-to-add-php-code-to-wordpress-post-or-page\">Add PHP to WordPress<\/a><\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&rsquo;s start by exploring the basics of WordPress shortcodes. What Exactly is Shortcode? Shortcode is a snippet of code, [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/my\/tutorials\/wordpress-do_shortcode\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":144,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"WordPress do_shortcode: What It Is and How to Use It","rank_math_description":"Extend your site's functionality through WordPress do_shortcode function. In this article, we will show you how to apply it!","rank_math_focus_keyword":"wordpress do_shortcode","footnotes":""},"categories":[22632],"tags":[],"class_list":["post-4521","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-usar-do-shortcode-wordpress","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/do_shortcode-wordpress","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/usar-do_shortcode-wordpress","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/do_shortcode-wordpress","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/usar-do_shortcode-wordpress","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/usar-do_shortcode-wordpress","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/usar-do_shortcode-wordpress","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-usar-do-shortcode-wordpress","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/wordpress-do_shortcode","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/wordpress-do_shortcode","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/4521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/users\/144"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/comments?post=4521"}],"version-history":[{"count":38,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/4521\/revisions"}],"predecessor-version":[{"id":126517,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/4521\/revisions\/126517"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media?parent=4521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/categories?post=4521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/tags?post=4521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}