WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get the top level category parent which is "wedgwood" so i give it a different menu and different template that what i wrote so far but it dont apply except on ‘wedgwood’ category wegdwood is my top level category i want this to be applied to all categories underneath it

in header.php

if (is_product_category(‘wedgwood’)) {
wp_nav_menu(array(‘menu’=>’wedgwood-menu’ ));
//I want to add here the code that links to another template which is wedgwood-template.php

in functions.php

//register the custom menus
function register_my_menus() {
array(‘wedgwood-menu’ => __( ‘Wedgwood Menu’ ))
); }
add_action( ‘init’, ‘register_my_menus’ );

So please i need a solution for this

share|improve this question

WP native function get_queried_object() can help you to get an ID of a currently displayed term.

WooCommerce then includes this handy function: woocommerce_get_term_top_most_parent() (originated here on WPSE btw,) that will get it's top-level parent term.

I haven't tested the following code but it should provide a good starting point:

if ( 'wedgwood' == woocommerce_get_term_top_most_parent( get_queried_object()->term_id )->slug ) {
    // your code-fu here ...

Regarding the template redirect part of your question - take a look at:
Creating a default Custom Post Template that a Theme can override


share|improve this answer
Looks like woocommerce_get_term_top_most_parent() doesn't exist anymore! – Alexandre Lavoie Sep 11 '14 at 19:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.