Site logo

Archived topic

different logo each main category + subcategories

10 replies · Started by Tim on May 8, 2020

Viewing posts 1–11 of 11

Hello,

We made 6 different logo's for headers using elements for our main categories. This works perfectly. We can select where to show. We have 500 categories in our shop and we would like to the subcategories also show the logo of our main category is this possible in a simple way? selecting all pages is not an option with the amount of categories we use.

http://www.degros.nl

Thanks in advance!
Tim

Hi there,

So are there only 6 parent categories which different logos, then 500 sub-categories that should inherit the parent logo?

Let me know :)

Hi Tom

Yes the parent logo of the particular main category should be set for its subcategories

Thanks
Tim

You may be better off using a function in this case instead of Elements.

Will these logos apply to all posts within these categories, and the category archives themselves? Or just the archives?

The logic is likely going to be somewhat complicated, so trying to get a clear picture.

Thanks!

Hi Tom

It will apply only for archive categories as products may appear in different categories.

So for home, product, cart, checkout and normal pages the normal logo should be shown (with 6 dots)

Thanks
Tim

Let's give it a shot:

add_filter( 'generate_logo', function( $url ) {
    $category = get_queried_object();
    $category_id = isset( $category->term_id ) ? $category->term_id : '';

    if ( is_category( 123 ) || term_is_ancestor_of( 123, $category_id, 'product_cat' ) ) {
        $url = 'URL TO LOGO FOR CATEGORY ID 123 OR CHILDREN';
    }

    if ( is_category( 456 ) || term_is_ancestor_of( 456, $category_id, 'product_cat' ) ) {
        $url = 'URL TO LOGO FOR CATEGORY ID 456 OR CHILDREN';
    }

    if ( is_category( 789 ) || term_is_ancestor_of( 789, $category_id, 'product_cat' ) ) {
        $url = 'URL TO LOGO FOR CATEGORY ID 789 OR CHILDREN';
    }

    // And so on..

    return $url;
} );

Hi tom,

thanks for this!

it does not work yet. i did this to test, but nothing happens to the subcategories of this main category:

https://www.degros.nl/product-categorie/pedicure-groothandel/

add_filter( 'generate_logo', function( $url ) {
$category = get_queried_object();
$category_id = isset( $category->term_id ) ? $category->term_id : '';

if ( is_category( 311 ) || cat_is_ancestor_of( 311, $category_id ) ) {
$url = 'https://www.degros.nl/wp-content/uploads/2020/02/groep-9.svg';
}

return $url;
} );

Works like a charm!

Thanks Tom, much appreciated!

hi tom one question, sorry. it does not work for mobile correct? we use mobile header

This archived topic is closed to new replies.