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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
14 views

Cannot get user's ACF data when using a template part in a WP_User_Query

I'm using a template part to repeat the HTML for each result when performing a WP_User_Query to return a list of users. However I am finding that the Advanced Custom Fields data isn't returning. // ...
greatsplott's user avatar
0 votes
0 answers
33 views

Access to a data from a response AJAX called in a template file php

I use an ajax called to get all posts of a custom post type and other criteria. I would like to get the response of my ajax called and use it in a template php file. So my question is : how can I pass ...
davidb45's user avatar
0 votes
0 answers
20 views

Separate page for pagination possible?

This is how my index.php looks like for my custom theme (I'm not sure if Line 4-5 is necessary). When I put pagination in the home or post, I would like to be able to take the user to a separate ...
Elaine Byene's user avatar
0 votes
1 answer
969 views

Template not loading with get_template_part or locate_template

I have this simple template in a my_template.php file: <div class="popup_canvas_container"> <p>This is a template I'm gonna load</p> </div> And I implemented ...
Luigino's user avatar
  • 103
0 votes
1 answer
2k views

Using ob_start and ob_get_clean with wordpress shortcode

I am including HTML template in my shortcode by using ob_start & ob_get_clean. Everything works normally but the returned HTML structure is broken. this is how I am inlcuding the html template in ...
StealthTrails's user avatar
0 votes
1 answer
395 views

How to declare a variable in a loop and make it available in the template file

I was faced with a minor issue but can't solve it myself. I need to add the value on the variable after all loop iterations. And nothing problem, but I need to use this variable in the other file. for ...
Victor Sokoliuk's user avatar
0 votes
0 answers
253 views

For which reasons can get_template_part's $args fail to work? (WP 5.8.1 - PHP 7.4.23)

I'm a big fan of the introduction of the $args parameter in get_template_part() since WP 5.5... or rather I would be, since I can't make it work and must still rely on [set|get]_query_var(). The call ...
Marks's user avatar
  • 31
0 votes
0 answers
459 views

how to replace h1 entry title with h2 in category pages only

This is the function im using: function change_title_h1_h2( $title, $id = null ) { return '<h2>'.$title.'</h2>'; } add_filter( 'the_title', 'change_title_h1_h2', 10, 2 ); Is there ...
will's user avatar
  • 9
0 votes
0 answers
60 views

Load templates, pass arguments, and render output from functions.php

I can't seem to find a solution to actually loading a template, passing arguments to it, executing it, and displaying the results from a shortcode registered via functions.php Is this even possible? I ...
WASasquatch's user avatar
0 votes
2 answers
233 views

Custom wp_query inside a conditional stament inside a template part doesn't work: why?

this is a bit messy and I cannot understand why my approach isn't working or what my error is. I'm using a template part to include a custom wp_query into my theme. I'd like to have two different ...
Gatto Nero's user avatar
0 votes
1 answer
312 views

Contain multiple page templates in one PHP custom template file in Wordpress?

As we know that WP has a feature called Page_Templates. But today, I got a question in my mind that can we add/use/access multiple page templates from single .php file (which is responsible to call ...
user avatar
0 votes
0 answers
36 views

Using the get_template_part method within an mu-plugin not possible?

A while back, I had someone here help me craft a custom mu-plugin (aka: "must use" plugin) that was designed to specially handle 404 server responses. Here is that thread for context, ...
Yvan Gagnon's user avatar
1 vote
1 answer
737 views

Filter get_template_part() $args array

I'd like to be able to pre-populate all occurances of the get_tempate_part $args when setting up a theme. get_template_part( string $slug, string $name = null, array *$args* = array() ) Several ...
dj.cowan's user avatar
  • 155
0 votes
0 answers
53 views

Can I set a global base path for get_template_part?

Is there a way to apply a global setting, so that get_template_part always uses a predefined base path? For example, I always put my templates in a directory called 'template-parts', and it'd be nice ...
verism's user avatar
  • 206
1 vote
0 answers
63 views

Don't see add_filter result in the site front page

I modified the site title the 'the_title' filter. I am using ACF pro repeater, I want to achieve is that if there is content in the repeater a + will be added to the post title. I wrote this script: ...
DavSev's user avatar
  • 143
0 votes
1 answer
780 views

Headers already sent error with get_template_part in REST API call

Crosspost from StackOverflow I've looked at multiple other questions about this warning (Headers already sent...etc) and this thorough explanation, but I'm not finding a solution for the circumstances ...
Nico's user avatar
  • 3
1 vote
1 answer
370 views

Template part inside shortcode, unexpected reult

I am attempting to call a template part via a shortcode. Ive read all about how to do this over and over on this site and yet after having tried a number of things still am unable to call a simple php ...
Ted's user avatar
  • 33
0 votes
1 answer
358 views

How to pass a variable to get_template_part that's updated every time the template part is called?

I have a loop and in that loop I use a get_template_part to call the HTMl for the post to display. I also have a variable (number) to which +1 is added every time the loop runs. In this way I can ...
ralphjsmit's user avatar
0 votes
1 answer
75 views

Adding a second loop breaks everything

I have a page template that has the following: <?php get_template_part( 'include', 'certifications-popular' ); ?> Within this file, I have two loops. But having the second loop in there seems ...
user avatar
0 votes
0 answers
697 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 ...
flintsburg's user avatar
0 votes
0 answers
25 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 ...
omid chahardoli's user avatar
0 votes
2 answers
3k views

get_template_part for template in subdirectory not working

I'm working on my first wordpress site, and moving it online. I have been adding some extra templates to design a simple booking engine, that was working perfectly on my offline localhost server. ...
AmLam's user avatar
  • 1
0 votes
1 answer
43 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 ...
ahmet kaya's user avatar
1 vote
0 answers
17 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 ...
quikina's user avatar
  • 23
1 vote
1 answer
2k views

add active class based on permalink and url

i am facing a issue, on my wordpress site in left side i loaded post list with title and excerpt, and when you click on that content will get load on right side of page and its working fine but i ...
arjun kushwah's user avatar
0 votes
1 answer
273 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, ...
Kevin4fm's user avatar
0 votes
2 answers
35 views

Blog template with different header to rest of site

I would like to change one thing on my wordpress custom template - there are big image sliders used throughout the site except on the contact us, checkout and my account pages. The blog page was added ...
MarvynH's user avatar
0 votes
0 answers
278 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 ...
Mohamed Mokhtar's user avatar
1 vote
0 answers
260 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 ...
Michael Gearon's user avatar
0 votes
2 answers
2k views

get_template_part for specific page

I have tried adding a file inside my header.php, but it will not load correctly. I get this error: Fatal error: Uncaught Error: Call to undefined function get_tempalte_part() Here is my markup ...
Anake.me's user avatar
  • 246
1 vote
1 answer
336 views

Overriding of the template for the Attachment “thumbnails” in the Media Grid isn't working

I'm trying to customize the template of the Media Browser (when clicking on "Add Media" button within Edit Post page), by adding a caption with the filename on each thumbnail so I don't need to select ...
Daniel Sian's user avatar
0 votes
1 answer
1k 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 ...
Irene88's user avatar
1 vote
3 answers
2k views

ACF Relationship + WP Template Parts

Any help with this would be greatly appreciated - I've been grappling with it for days :) I have 2 post types - product + offer I have an ACF relationship field related_products. This field ...
user avatar
0 votes
1 answer
172 views

Using same variable names in files added with get_template_part()

Say I have a file named content-header.php and content-body.php. In content-header.php I have this variable: $some_var = 'apples'; and in content-body.php I have a variable with the same name but ...
at least three characters's user avatar
0 votes
0 answers
1k 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, ...
AaronJ's user avatar
  • 101
2 votes
2 answers
2k views

add a hook with get_template_part()

I have this hook. How i can add this hook with get_template_part()? I created a file "myfile.php" where I store the HTML code of my search bar, but a can't manage to connect my template add_filter('...
Asking's user avatar
  • 121
0 votes
0 answers
141 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 ...
Runnick's user avatar
  • 1,169
0 votes
1 answer
100 views

Remove a short code and update it's content (AJAX)

This is my code function ajax_layoutcontrol(){ if( !check_ajax_referer( 'special-string','security')){ return wp_send_json_error( 'Invalid nounce'); } if (! current_user_can('...
user avatar
0 votes
1 answer
481 views

How to get value from radio buttons meta box, and return different contents?

I have a multiple checkbox type question (using Ultimate member) storing values as user meta. The question basically asks the user what he wants, and according to what he wants, I would like my ...
Damien Ramage's user avatar
1 vote
0 answers
126 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 ...
feedmeimhungry's user avatar
2 votes
1 answer
531 views

Problem with using get_template_part() in footer

First off let me just say, I'm new to theme development, I hope there isn't something obvious I'm missing. I'm trying to get this form contactform.php <form method="POST" action=""> <...
Žiga Stupan's user avatar
2 votes
1 answer
364 views

how to remove get_template_part from a plugin? [closed]

I have a template file and that file has two get_template_part(). ie,get_template_part( 'store' ); get_template_part( 'header' ); these two are used inside a template page, I wanted here to ...
guest's user avatar
  • 39
0 votes
1 answer
746 views

get_template_directory_uri() not working

I am getting trouble with the following lines of code. Actually I have created a custom file confirm_email.php in which I wrote the following piece of code. When I'm removing $temp_dir variable it ...
Mohd Hasan's user avatar
0 votes
1 answer
1k views

How to reuse get_template_part() containing a simple loop to work with AJAX correctly?

I've got simple loop in standard-loop.php file (which, the file, is located in inc/loop folder): if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); ...
Daniel's user avatar
  • 181
0 votes
2 answers
1k 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 ...
user658182's user avatar
1 vote
1 answer
272 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 ...
sugarfiend's user avatar
0 votes
1 answer
150 views

How to limit the number of Related Posts?

In my theme's file single.php, there is this part of code to get Related Videos: <?php if ( $wp_query ->have_posts() ) { while (have_posts()) : the_post(); ...
Devilix's user avatar
  • 103
0 votes
2 answers
310 views

get_template_part causes 500 error

I am trying to list posts in a widget I am working on at the moment. However, when I use the get_template_part function in my loop, my site just keeps loading until I get a 500 http error. $args ...
TheKidsWantDjent's user avatar
1 vote
1 answer
850 views

Modify foreach loop for social sharing links?

How would I amend the following foreach loop so each link displays the keys from each nested query, and not just the values? I am creating my own social sharing links, included using get-template-part,...
user avatar
0 votes
1 answer
800 views

Insert template-part inside the content

I want to display an image/banner with link, inside the content of the posts of my blog. Neither at the beginning, nor at the end. It should appear somewhere inside the content of the post. I don't ...
IXN's user avatar
  • 906

1
2 3 4 5