get_template_part() does not work if you call it when you are in a subfolder

get_template_part() will work the same no matter where or how deep you are within your theme. It always includes relative to the theme (or child theme) root. So if you call the following from anywhere: get_template_part( ‘content’, ‘job-listing’ ); … it will try to load (in order): child-theme/content-job-listing.php parent-theme/content-job-listing.php child-theme/content.php parent-theme/content.php To load parts that … Read more

Too many get_template_parts?

In my opinion three or four calls of get_template_part() is perfectly acceptable and even within the norm for some of the larger and more complex themes out there. I don’t know how many is too many but I think it would have to be a pretty large number to notice a hit in performance. A … Read more

Combining shortcode and get_template_part

Try this function get_products($atts) { ob_start(); get_template_part(‘block-products-inline’); return ob_get_clean(); } add_shortcode(‘products’, ‘get_products’); Little explanation php just outputs your content right away when its see print statement. What we do here is, we are holding all the output in buffer and not giving it in print until the whole things finish. then we are returning the … Read more

get_template_part from plugin

/** *Extend WP Core get_template_part() function to load files from the within Plugin directory defined by PLUGIN_DIR_PATH constant * * Load the page to be displayed * from within plugin files directory only * * @uses mec_locate_admin_menu_template() function * * @param $slug * @param null $name */ function mec_get_admin_menu_page($slug, $name = null) { do_action(“mec_get_admin_menu_page_{$slug}”, $slug, … Read more

How to add custom content template part for a custom post type on main query using a plugin

Background Unfortunately get_template_part() function doesn’t have any suitable filter to achieve what you want. It’s possible to use the get_template_part_{$slug} action hook to inject template parts, however, without any change to your theme or a child theme, the original template part will be added anyway. So this way you’ll not be able to replace existing … Read more

When is get_template_part() preferable to simply using the template.php files?

A recommended approach for using get_template_part would be for including bits of code that would otherwise be repeated frequently in all your templates. Like if you had conditionals defined within your loop that you wanted to include in archive.php, search.php, single.php etc. It also allows child themes to override that file and include additional more … Read more

How to make get_template_part always check child theme first?

It does, by default. The get_template_part() function uses locate_template() which cascades through the template files in in order of specificity and stylesheetpath/templatepath. So, if your Child Theme includes a content-inventory.php, then get_template_part() will include it; if not, then it will look for content-inventory.php in the parent Theme. If it doesn’t find it, it will then … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)