{"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><figure class=\"wp-block-image size-large\"><a href=\"\/my\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"2048\" height=\"600\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/45\/2024\/06\/New-WP_in-text-banner.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/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            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Discover More Expert WordPress Techniques                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><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        \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-GB","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}]}}