Archived topic
Alternate logo with filter on certain pages not working
4 replies · Started by Jordan on January 25, 2021
Hey there!
I'm trying to swap the logo image on a series of pages (testing on this page https://bayoubutlersauces.com/rojizo/) that align with the products that'll be reflected on those pages. I used the filter suggestion here and modified it slightly to be the following code, but haven't been able to get any results.
add_filter( 'generate_logo', function( $logo ) {
// Return our category logo URL
if ( is_page(191) ) {
return 'https://bayoubutlersauces.com/wp-content/uploads/2021/01/Rojizo-Logo.png';
}
// Otherwise, return our default logo
return $logo;
} );
I also tried to modify the href and was successful with this code, so I know the site is seeing my updates, but something must be off with my code for changing the image.
add_filter( 'generate_logo_href', function() {
if ( is_page(191) ) {
return "https://google.com";
}
} );
Thanks so much!
Hi there,
i think its working, but you also have the Retina Logo selected in the Customizer, which uses this filter: generate_retina_logo
So keep your current logo filter and make a copy of that and switch the filter to generate_retina_logo
Amazing! Thanks David. I ended up realizing I need to be doing this with the Woocommerce category pages. The following code works great.
add_filter( 'generate_logo', function( $logo ) {
// Return our category logo URL
if ( is_product_category('rojizo') ) {
return 'https://bayoubutlersauces.com/wp-content/uploads/2021/01/rojizo-logo.svg';
}
// Otherwise, return our default logo
return $logo;
} );
add_filter( 'generate_retina_logo', function( $logo ) {
// Return our category logo URL
if ( is_product_category('rojizo') ) {
return 'https://bayoubutlersauces.com/wp-content/uploads/2021/01/rojizo-logo.svg';
}
// Otherwise, return our default logo
return $logo;
} );
However this doesn't trickle down to the products under that category. Is that even possible behavior to implement?
Ended up finding the answer. Posting here for others.
add_filter( 'generate_logo', function( $logo ) {
$term_slug = 'rojizo';
$taxonomy = 'product_cat';
$term_id = get_term_by( 'slug', $term_slug, $taxonomy )->term_id; // Get the term ID
$child_ids = get_term_children( $term_id, $taxonomy ); // Get the children terms IDs
$terms_ids = array_merge( $child_ids, [$term_id] ); // an array of all term IDs (main term Id and it's children)
if ( has_term( $terms_ids, $taxonomy, $product_id ) ) {
return 'https://bayoubutlersauces.com/wp-content/uploads/2021/01/rojizo-logo.svg';
}
// Otherwise, return our default logo
return $logo;
} );
Thats great! Thanks for sharing your solution