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.

34 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
14 views

ä/ü/… are not displayed when including via get_template_part()

I just have the problem that characters like ä and ü appear as question marks when I include something via get_template_part(). Does anyone know what this could be? Everywhere else the letters are ...
1
vote
0answers
108 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
47 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
77 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
869 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
538 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
335 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
49 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
101 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
273 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
593 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
19 views

get_template_part() break bootstrap row columns layout

I'm having some trouble to get my boostrap layout working in wordpress. I want to show some posts on a single row with a loop that show the content inside a col-8 and another loop that show the ...
0
votes
0answers
12 views

When to use get_template_part versus a function

What are good guidelines on when to use get_template_part() versus code in functions? I have both throughout my theme, and I think I've used them correctly, but I'm suddenly not sure I can articulate ...
0
votes
0answers
42 views

Ajax and get_template_part

I found this https://stackoverflow.com/questions/33999193/wordpress-load-more-posts-onclick-with-ajax-request-jquery to load posts via Ajax. It works great except that I would like to use a template ...
0
votes
0answers
20 views

how to use a different template (index.php) in wordpress

I want to choose the best way to separate the mobile template and the desktop. Is this the right way? If I put this code in the index.php file: <?php if ( wp_is_mobile() ) : ?> <?php ...
0
votes
1answer
29 views

Is_Page doesnt detect my page

I want to call Servicedeneme.php which is in main folder of theme, in mysite.com/faq/ It's title is FAQ so I write code for two form which are faq and FAQ.However, it doesnt work. I write below code ...
0
votes
0answers
9 views

Can I load sections like get_template_part for a one pager website?

I'm building a web page with everything on just one page, nothing revolutionary. I'm doing it in a child-theme and have created a new template page for it. I just wonder if it's possible to, instead ...
0
votes
0answers
12 views

Nest HTML content between template part

Apologies for the lackluster title. I am curious if there's something similar in Wordpress as Nunjucks call or block. Essentially, I am curious if it is possible to create a template part and inject ...
0
votes
1answer
54 views

What are the benefits of using get_template_part()?

I can find lots of "how" answers in reference to using get_template_part(), but no "why" except that it can cut down the amount of code to be written. I'm asking this from an end user's perspective, ...
0
votes
0answers
30 views

What is better for passing variables to templates - include(locate_template.. or $wp_query->query_vars?

The answers here: Passing variables through locate_template are extremely helpful in solving the problem of passing variables to templates such as sidebar and footer. In short, which is best? ...
0
votes
0answers
85 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
243 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
437 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
52 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
401 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
127 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
243 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
240 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
1k 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
34 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 ...