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.
207 questions
0 votes
0 answers
61 views
Loading template part programatically, inline styles missing
<?php /** * Data provider for block patterns. * * @package Test */ namespace RomArt\DataProviders; /** * BlockPatternsDataProvider class. */ class BlockPatternsDataProvider extends ...
0 votes
1 answer
34 views
get_template_parts() usage
I am trying to add a template sections that I have in a directory my-child-theme/template-parts/hero.php. In my page template (my-child-theme/templates/front-page.php) I am calling echo ...
1 vote
0 answers
41 views
Get_Template_Part and Template files in TwentyTwentyFour Block Editor
I am building a project using WordPress 6.6.1. I have opted to create a child them which extends TwentyTwentyFour and therefore relies on the new block editor which is packaged in that parent theme. ...
1 vote
1 answer
68 views
Wordpress "Blog" template hierarchy
When I open up my WordPress site, and on the admin - settings - reading I define Your home page display posts as "Your latest posts" The homepage is displayed by home.php and /blog/ is ...
0 votes
1 answer
241 views
Multiple queries and pagination
I have a homepage and an archive page where I call a template part to have a hero section for the most recent posts, and then loop through the remaining posts as usual. Essentially I don't want to ...
0 votes
1 answer
85 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. // ...
0 votes
0 answers
64 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 ...
0 votes
0 answers
39 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 ...
0 votes
1 answer
2k 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 ...
0 votes
1 answer
3k 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 ...
0 votes
1 answer
567 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 ...
0 votes
0 answers
388 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 ...
0 votes
0 answers
639 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 ...
0 votes
0 answers
109 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 ...
0 votes
2 answers
281 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 ...