Site logo

Archived topic

Add a specific link in a Logo (Page Header)

19 replies · Started by Mario on January 29, 2017

Viewing posts 1–15 of 20

Dear Tom,

In some pages I want my header image to be different. I go through the Page Header option, in the Logo tab. I select the logo, by clicking Choose logo (Overwrite your site-wide logo/header on this page). Everything is fine. But I would like this particular logo to link a specific page and not the original page of the original header.

How can this be accomplished?
I am using GP 1.3.41.

Thanks

Hi Mario,

You can use the generate_logo_href filter for that.

add_filter( 'generate_logo_href','generate_add_custom_logo_href' );
function generate_add_custom_logo_href()
{
    if (is_page( 'your-page-slug' ))       
        return 'http://yourURL.com';
}

Adding PHP: https://docs.generatepress.com/article/adding-php/

Let me know if this helps

Dear Leo,

I don't know where this filter is located nor where to copy/paste the code.

Thanks

Please see the Adding PHP page I provided under the code.

You would need to replace your-page-slug and http://yourURL.com

Page slug is shown in your permalink. So for http://vivaelsoftwarelibre.com/open-source-academy-osdemy/ it should be
open-source-academy-osdemy

Hope this helps.

Thanks for the quick answer.
Which link I should copy in http://yourURL.com?
The osdemy webpage linked before or the page where this new customized header is?

The new page link that you want to replace the default link.

Perfect. And one last question. There would be more than one page with this customized header (but the same one). How would the code be?

add_filter( 'generate_logo_href','generate_add_custom_logo_href' );
function generate_add_custom_logo_href()
{
    if (is_page( 'open-source-academy-osdemy' ))       
        return 'http://yourURL.com_1';
        return 'http://yourURL.com_2';
        return 'http://yourURL.com_3';
}

Multiple pages with the same link? If so something like this:

add_filter( 'generate_logo_href','generate_add_custom_logo_href' );
function generate_add_custom_logo_href()
{
    if (is_page( 'open-source-academy-osdemy' ) || is_page( 'page-slug-2' ))       
        return 'http://yourURL.com';
}

Thanks for your responses.

I meant the other side. Multiple pages with the same customized header linking this header to the osdemy web.

Sorry I'm a bit confused. You the logo of each page to link to a different site?

I am gonna try to explain carefully.

In my webpage (www.vivaelsoftwarelibre.com) I have an "official" header that automatically links to the home. But in some posts and pages (definitively more than one), I have changed the header for an "unofficial" one (let me say).

And I want that "unofficial" header to link to a specific page (not the home).

Hope in this way the issue is more understandable.

Thanks

Then you're on the right track.

You can do this:

add_filter( 'generate_logo_href','tu_add_custom_logo_href' );
function tu_add_custom_logo_href( $url )
{
    if ( is_page( 'open-source-academy-osdemy' ) ) {    
        return 'http://yourURL.com/specific-page';
    }

    if ( is_page( 'another-page' ) ) {
        return 'http://yourURL.com/another-specific-page';
    }

    if ( is_page( 'third-page' ) ) {
        return 'http://yourURL.com/third-specific-page';
    }

    // All the other pages
    return $url;
}

Hello again,

I have tried what you said with no success.
Look at this page, where the logo header has been replaced by the one you see in it (OSDEMY):
http://vivaelsoftwarelibre.com/net-developer-skills-enhancement-course/

Clicking on that header, it goes to http://vivaelsoftwarelibre.com/en/

I actually want that link to go to this webpage:
http://vivaelsoftwarelibre.com/osdemy-open-source-academy/

I installed the Snippets plugin and activated this code:

add_filter( 'generate_logo_href','tu_add_custom_logo_href' );
function tu_add_custom_logo_href( $url )
{
    if ( is_page( 'open-source-academy-osdemy' ) ) {    
        return 'http://vivaelsoftwarelibre.com/net-developer-skills-enhancement-course/';
    }
    return $url;
}

But the link keeps going to the home instead to the OSDEMY webpage. What's wrong?

This archived topic is closed to new replies.