{"id":6220,"date":"2017-01-17T19:58:17","date_gmt":"2017-01-18T00:58:17","guid":{"rendered":"https:\/\/themespress.ca\/?p=6220"},"modified":"2022-09-03T20:41:50","modified_gmt":"2022-09-04T00:41:50","slug":"using-get_template_part-in-wordpress-template","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/using-get_template_part-in-wordpress-template\/","title":{"rendered":"Using get_template_part in WordPress Template"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In this tutorial, we will show you how to use the  get_template_part in your WordPress templates in order to logically structure things in our WordPress theme.<\/p>\n<p>The <strong>get_template_part()<\/strong> function allows users to call a file in multiple templates at once in order to simplify dynamic integration.<\/p>\n<h2>What can we use with the get_template_part() function?<\/h2>\n<p>Breadcrumbs, Archive titles, filters, loop posts, etc&#8230;<\/p>\n<p><strong>In your theme&#8217;s root folder, we will need a new folder called template-part.<\/strong> This new folder will contain all necessary files that will be executed by the get_template_part() function.<\/p>\n<p>In the example below, we will use the get_template_part() function for our Breadcrumbs with the <strong>Yoast SEO<\/strong> breadcrumbs.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8765438\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-8765438\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php if(function_exists(&#039;yoast_breadcrumb&#039;)) { ?&gt;\n  &lt;div id=&quot;breadcrumbs&quot; class=&quot;bg-light py-3 text-muted&quot;&gt;\n    &lt;div class=&quot;container&quot;&gt;\n      &lt;?php yoast_breadcrumb(); ?&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;?php } ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In your template-part folder, create a new breadcrumbs.php file and add the code snippet below:<br \/>\n<!--?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('\n\n\n \n\n\n\n<p id=\"breadcrumbs\">','\n\n\n \n\n\n'); } ?--><\/p>\n<p>In your desired template, you&#8217;ll be able to call the file for your breadcrumbs.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-1811731\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-1811731\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php get_template_part( &#039;template-part\/breadcrumbs&#039; ); ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>As you might have noticed, the get_template_part() contains the folder name (<strong>template-part<\/strong>), and then the file name(<strong>breadcrumbs<\/strong>). You can call it in all templates necessary.<\/p>\n<p><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_template_part\/\" target=\"_blank\" rel=\"noopener\">Learn more about the get_template_part() function<\/a><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"In this tutorial, we will show you how to use the get_template_part in your WordPress templates in order to logically structure things in our WordPress theme. The get_template_part() function allows<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/using-get_template_part-in-wordpress-template\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4585,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318],"class_list":["post-6220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6220"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6220\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4585"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}