Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [get-template-part]

It is a WordPress core function that loads template parts inside theme templates. It makes it easy for themes to reuse sections of code like pagination, header images, menus, etc.

24 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
27 views

Unable to include a template

On the home.php, which is in the same folder where style.css is kept I am try to call a template: <?php get_template_part( 'template-parts/content', 'home-default' ); ?> template-parts is a ...
1
vote
0answers
15 views

Showing the WordPress standard text area on a Woocommerce Single Product Page?

I'm trying to show the WordPress default text area on a Woocommerce Single Product Page but can't find the appropriate hook to add to the template? I would have thought it would've been well ...
1
vote
0answers
35 views

Styles and scripts inside template part

Is there anything wrong with including style and script tags inside a template part? The template part which I'm using like something more similar to a vue/react component is working correctly but ...
1
vote
1answer
35 views

How to show “teaser” posts on blog / archive pages, otherwise full posts

Forgive me, I'm a PHP noob and writing too much of it makes my eyes glaze over; I'm sure this is a super simple solution and probably a dumb question. I'm working on a custom theme where I want to ...
1
vote
1answer
644 views

get_template_part based upon post's category

I have a WordPress website setup with 5 main parent categories each with dozens of child categories For each WordPress post in single.php, I'd like to load some content based upon each child category ...
1
vote
0answers
433 views

Modal working only on home page

I have created a modal pop up using JavaScript. The HTML for the modal is in a get_template_part("content","contact")` file. The issue is, only on the home page does the modal pop up Through a click ...
1
vote
1answer
222 views

Detect if current page is front page within custom query

I am currently working on a project where we're designing a custom frontpage template for a static front page. Within the template are three different custom WP_Queryies with relating loops. Within ...
1
vote
1answer
46 views

Is there any problem if I use get_template_part like this?

I want to display different content on my home page and in single pages, so I am using the following code in index.php: get_template_part( 'template-parts/content-home', get_post_format() ); At ...
1
vote
0answers
78 views

Loading template parts conditionally in Customizer

Here are my issues: I have layout options in customizer for full width or two columns. For fullwidth sidebar will not be loaded. The problem is if the setting is currently on full width when ...
1
vote
1answer
228 views

How to use taxonomy term as a value of get_template_part?

I would like to dynamically import different template parts (hardcoded sidebars or navigations) into my layout based on a taxonomy assigned to the post. For instance, this "standard" code works as ...
1
vote
1answer
504 views

Change the file path on get_template_part via plugin

I'm trying to make a plugin that will change the behavior of a theme. In the theme file I have a get_template_part('libs/templates/user_menu');. I want to make my plugin "force" the ...
0
votes
0answers
26 views

do_action doesn't trigger if it's in a template that gets loaded via REST endpoint

i'm building a single page application using woocommerce and custom REST endpoints to get template parts and load them into the browser ... one endpoint is getting content-single-product.php template ...
0
votes
1answer
42 views

Shortcode and get_template_part

I'm developing my own plugin for my wordpress. I create a shortcode for my plugin and CPT with a custom taxonomy and custom single-CPT. When I try to use the function get_template_part() in my ...
0
votes
0answers
87 views

Display a custom 404 page without a redirect

In a plugin I want to display a specific page without redirecting (and thus without changing the URL) like the plugin https://wordpress.org/plugins/404page/ does. I can capture 404s and redirect them, ...
0
votes
0answers
23 views

get_template_part calls amount and performance?

I'm trying to build the theme that is easily customizable by other developers and chose to go get_template_part route so files can be easily overwritten in child theme. My question is there some ...
0
votes
2answers
238 views

How can I show contents of a template part inside of another page?

Wordpress is of course made up of templates and the template parts that make up those templates. I know I can override the template parts - that's not what I'm trying to do here. I'm trying take the ...
0
votes
1answer
112 views

Looking to load a different template part on every load/refresh

I basically have a site where I have several different template headers that I want to load via get_template_part. The basic idea is when someone first visits the site, they should see a random ...
0
votes
1answer
234 views

Include template file from plugin to theme

I am using a plugin in my theme options. I copied the entire plugin directory in my child theme directory and correctly included all the files in the theme functions.php. The plugin options files is ...
0
votes
1answer
210 views

get_template_part doesn't output all data

I hope I get some help with get_template_part function. my starting point is a contact-us template (it's got map+address+emailform) that stores data in the database my other template is where I have ...
0
votes
0answers
838 views

Using require_once for parent-directory not working but is working in sub-directories

I'm building a custom theme and I'm attempting to use require_once __DIR__ . '/templates/variables.php' in my footer.php file, to keep from repeating code that contains variable information... I keep ...
0
votes
0answers
33 views

How to unregister sidebar for template_part?

Can you help me please? I have this code in my index.php: php get_sidebar(); And I have a template_part 'loop-fullwidth', which I call in index.php. I need to register sidebar for index.php and ...
0
votes
1answer
44 views

Is this correct get_template_part() in WordPress?

I just want to show the slider structure if it has posts... is this correct? <?php if ( (have_posts() ) { get_template_part('slider'); } ?> I think that works but I'm not sure if is ...
0
votes
0answers
143 views

query_post while (have post) get_template_part()?

My goal: Is to give the user the ability, if they so choose, to create a new category. I have the current categories saved in a separate php file and call them in using get_template_part(), there ...
-1
votes
2answers
1k views

First post outside of loop, homepage only?

Because of the way my templates are structured, I need to pull the first/sticky post from the site outside of the standard loop, just on the homepage. I'm using _s (underscores.me) as a base, so the ...