Site logo

Archived topic

Replace my site logo with a different one on a specific page or category

18 replies · Started by Michelle on July 18, 2022

Viewing posts 1–15 of 19

I've implemented several different php codes for this that I found on this forum, but can't get them to work without a php error.

I have a fixed site logo on all pages. I want a different logo on one page of my site. I will settle for having it on a category if that is easier. How do I do this?

Thanks!

Yes, that was the first one I implemented.

Can you try adding the code again, and provide the specific link to the page you’re trying to change the logo of? I’ll check what’s causing it not to work.

Thank you. I am now working on a staging site until I get it straight. Below are my login credentials. David's code is in Snippets

Thanks!

Can you try this?:

add_filter( 'generate_logo', function( $logo ) {
      // Return our category logo URL
    if ( 6619 === get_the_ID()) {
        return 'https://cdn.reachingmyworld.com/wp-content/uploads/2022/06/18162522/Daily-Reach-Logo-For-Site.png';
    }

    // Otherwise, return our default logo
    return $logo; 
 } );

add_filter( 'generate_retina_logo', function( $logo ) {
      // Return our category logo URL
    if ( 6619 === get_the_ID()) {
        return 'https://cdn.reachingmyworld.com/wp-content/uploads/2022/06/18162522/Daily-Reach-Logo-For-Site.png';
    }

    // Otherwise, return our default logo
    return $logo; 
 } );

Kindly let us know how it goes!

I tried it and could not get it to work. I did clear my cache.

As a temporary measure, I added the desired logo as an image and disabled the site logo. This is a "fix it with tape" method, but I'd like to have this work properly with php.

Still needing some help with this. The new logo doesn't show sticky on tablet or desktop, and still links to the homepage (noooooooo--------)

How do I continue to style this Element header?

1. Disable replacement logo's link to the homepage (not the main logo)
2. Sticky on scroll only shows on mobile. I want it to work on tablet and desktop too.

I added the code in Snippets, and then used Site Header in Elements, per Ying's suggestion. Below are my credentials for the Live Site. The staged site was misbehaving...

Would you know why is your menu not showing in the Daily reach page? Did you add a custom code to do as such?

Kindly let us know.

The Daily Reach logo IS showing up on the Daily Reach page. It just isn't sticky on desktop like I want it to be, and it still links to the homepage. I want to disable the link.

Let’s try to solve the sticky issue first.

I believe you’ve disabled the Primary Navigation in the Page settings. Doing so would also disable the sticky nav.

You’ll need to enable it to have the stick header on desktop and tablet.

Then, to set the URL of the logo, you’ll need this PHP:

add_filter('generate_logo_href', function($href ){
	if( 1431 === get_the_ID() ){
		$my_url = 'https://www.google.com';
			
		return $my_url;
	}
	
	return $href;
},10,1);

To set the image and url of the sticky header, you’ll need this PHP as well:

add_filter('generate_sticky_navigation_logo_output',function($output, $img_src, $image){
	if( 1431 === get_the_ID() ){
		$my_url = 'https://www.google.com';
		$logo_src = 'https://cdn.reachingmyworld.com/wp-content/uploads/2022/06/18162522/Daily-Reach-Logo-For-Site.png';
		$width = '150px';
		$height = '150px';
		return sprintf(
				'<div class="sticky-navigation-logo">
					<a href="%1$s" title="%2$s" rel="home">
						<img src="%3$s" class="is-logo-image" alt="%2$s" width="%4$s" height="%5$s" />
					</a>
				</div>',
				$my_url,
				get_bloginfo( 'name', 'display' ),
				$logo_src,
				$width,
				$height
			);
	}
	return $output;
}, 10, 3);

Replace google.com in both codes to your preference.

Kindly let us know.

This archived topic is closed to new replies.