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 slug that the post belongs to. i.e. if in category "letters > ABC", get_template_part abc.php i.e. if in category "letters > ABC" and "numbers > 123", get_template_part abc.php and 123.php etc At the moment I'm doing this the long and inefficient way of: <?php if (in_category( …
So, I need to debug an issue and I would like to see all template files that were used to render this specific page. I mean specific "sub" template files (not the main .php file), like sub woocommerce template files. For the main template file this works: add_action( 'wp_footer', function() { global $template; print_r( $template ); }); I get the main (last) template file used (eg. single.php). But I would really like to see all templates embedded with eg. wc_get_template …
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 get_template_part to return another slug file (a path to a file in the plugin's folder). So far this is my code inside the plugin: function wpse21352_template_part_cb( $slug ) { if(slug == 'user_menu') { return WP_PLUGIN_URL.'/'.$slug; } else { return $slug; } } do_action( "get_template_part_user_menu", 'user_menu' ); add_action( 'wpse21352_template_part_cb', 'get_template_part_user_menu', 10, …
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 HTML generated by said template part and display it elsewhere. How can I get the rendered HTML data from a template part for a given Page/Post ID and display it as part of another page, preferably as a shortcode? Here is an …
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 shortcode, the result is a call to a single.php template from the theme. How I can limit where get_template_part can look for files? This is my shortcode: function shortcode_display_products ( $atts ){ global $wpdb; $query = ''; $atts = shortcode_atts( array( 'categories' => '' ), $atts, …
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 this function to load the template from custom shortcode: public static function load_template($atts) { function load_my_template() { ob_start(); //if ( file_exists(TEMPLATE_MODULE_DIR . 'my-template.php') ) { // include_once( TEMPLATE_MODULE_DIR . 'my-template.php' ); //} get_template_part('my-template'); //locate_template( TEMPLATE_MODULE_DIR . 'my-template.php', true, true ); return ob_get_clean(); //global $wpdb; //$current_user_id = $wpdb->get_var( "SELECT user_email FROM newk3_users WHERE user_login = 'xxxxxx' " ); //$result …
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 my shortcode function. function return_cards_grid_section(){ //this variable is in the same file global $subsitesDetails; ob_start(); get_template_part('/templates/views/cards', null, [ 'subsitesDetails' => $subsitesDetails ]); return ob_get_clean(); } And below is my code for cards html file <section class="cards-in-grid-section mt-50"> <div class="p-10 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 gap-5"> <? …
I loaded some contents by ajax, When i try something like this: $resp = array( 'success' => true, 'data' => 'the content here' ); it's working without any issues but if i used something like this: $resp = array( 'success' => true, 'data' => get_template_part( 'templates/update', 'profile' ) ); it gives me SyntaxError: JSON.parse: unexpected keyword at line 1 column 1 of the JSON data. the content here{"success":true,"data":null} What's the problem with get_template_part?
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 example: while( have_posts() ) { the_post(); $x = ''; $x++; get_template_part( 'content', 'right' ); } Now I need to get the $x value with iteration in content-right.php I try to declare a variable into this file but in this case …
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 to get_template_part() is set in an archive template, like archive-whatever.php and goes like this: $args = array( 'my_var' => 'my_value' ); get_template_part( 'content', 'template-to-get', $args ); Then, as seen in every single example I've found, in content-template-to-get.php I do as follows: if ( $args['my_var'] == …
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 any way to just target the title of the posts in the category pages? thx!
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 would like to have editable template parts that are not hard-coded into the function. I tried output buffer, but it still doesn't get anything from the get_template_parts() functions, so I had to return to outputting HTML from the function. Edit: Would it be appropriate to just include/require …
I want to assign template for this plugin https://wordpress.org/plugins/job-postings/ since i have used custom template for all pages (created own) the post title section is not visible in this Job Listings page as well as Job Detail page i tried of creating child folder in my active theme with those files but its not reflecting (the way we do for customizing woocommerce plugin pages) Could someone share your ideas ?
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 behaviours throughout the theme, so I'm using a conditional statement inside the template part to output two different loops. In my front-page.php I call the template part with get_template_part() using the $args option: <?php get_template_part('template-parts/modules/moduli-offerta/offerta-figli','lista', array('tipologia' => 'lista') ); ?> In my …
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 page template.) For example first 40 lines of demo-xyz.php will echo a "demo" page template and then after left lines echo a "xyz" template. then i want to select both as page template for different two pages in wordpress>pages>addnew>page attributes>select page template. (there both 1.demo …
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, complete with the specific code I'm referencing: Question about repurposing WordPress 404 handler I'm just now revisiting this project and trying to resume development on it, but am running in to some issues with using the "get_template_part" method within the mu-plugin file .. trying to pull in specific …
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 action hooks exist within the get_template_part function and within locate_template which is also called by get_template_part, get_header, get_footer and the like but no filters are applied. The best I've been able to fashions is to modify every instance of my themes call to get_template_part like so: <?php get_template_part( 'views/loop', …
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 to not have to always include that in the first argument string. I know I could probably call a custom function that calls get_template_part, but I was wondering if there was a slightly more elegant way of doing it.
The WP Codex says to do this: // You wish to make $my_var available to the template part at `content-part.php` set_query_var( 'my_var', $my_var ); get_template_part( 'content', 'part' ); But how do I echo $my_var inside the template part? get_query_var($my_var) does not work for me. I've seen tons of recommendations for using locate_template instead. Is that the best way to go?
In this post on wordpress.stackexchange.com I asked whether using get_template_part(), as demonstrated in the TwentyTen theme, is a recommended best practice. The general consensus I got was that it was not necessarily the best practice in all situations. This related question then is: can you provide me with an example where using get_template_part() would be the recommended approach, over simply defining the separate template.php files? For example, I can either define archive.php, single.php and page.php; or I can define loop-archive.php, …