Site logo

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

Home Forums Support [Resolved] Replace my site logo with a different one on a specific page or category

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

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #2286874
    Michelle

    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!

    #2286882
    Fernando
    Customer Support

    Hi Michelle,

    Have you tried this code by David?: https://generatepress.com/forums/topic/change-logo-image-on-one-page/#post-1874727

    Kindly let us know.

    #2286928
    Michelle

    Yes, that was the first one I implemented.

    #2286943
    Fernando
    Customer Support

    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.

    #2287867
    Michelle

    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

    #2288057
    Fernando
    Customer Support

    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!

    #2288709
    Michelle

    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.

    #2288825
    Ying
    Staff
    Customer Support

    Hi Michelle,

    Actually, you can use a header element to upload different logo and assign it to specific pages. I don’t think PHP code is necessary.
    https://docs.generatepress.com/article/header-element-overview/#site-header

    #2288943
    Michelle

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

    #2288957
    Michelle

    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.

    #2289038
    Fernando
    Customer Support

    Where did you add the custom logo? Is it in the staging site or the the live site? Can you provide the link? Also, where did you add the code above?: https://generatepress.com/forums/topic/replace-my-site-logo-with-a-different-one-on-a-specific-page-or-category/#post-2288057

    Kindly let us know.

    #2289039
    Michelle

    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…

    #2289068
    Fernando
    Customer Support

    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.

    #2289078
    Michelle

    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.

    #2289130
    Fernando
    Customer Support

    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.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.