- This topic has 4 replies, 2 voices, and was last updated 3 years, 2 months ago by David.
-
AuthorPosts
-
January 25, 2021 at 1:08 am #1632318Jordan
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!
January 25, 2021 at 2:43 am #1632430DavidStaffCustomer SupportHi 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
February 16, 2021 at 9:50 pm #1661222JordanAmazing! 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?
February 16, 2021 at 10:08 pm #1661229JordanEnded 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; } );
February 17, 2021 at 3:30 am #1661481DavidStaffCustomer SupportThats great! Thanks for sharing your solution
-
AuthorPosts
- You must be logged in to reply to this topic.