- This topic has 19 replies, 3 voices, and was last updated 7 years, 2 months ago by Tom.
-
AuthorPosts
-
January 29, 2017 at 9:30 am #271239Mario
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
January 29, 2017 at 10:26 am #271284LeoStaffCustomer SupportHi 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
January 30, 2017 at 8:18 am #271736MarioDear Leo,
I don’t know where this filter is located nor where to copy/paste the code.
Thanks
January 30, 2017 at 8:29 am #271741LeoStaffCustomer SupportPlease see the Adding PHP page I provided under the code.
You would need to replace
your-page-slug
andhttp://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.
January 30, 2017 at 9:31 am #271765MarioThanks 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?January 30, 2017 at 9:34 am #271768LeoStaffCustomer SupportThe new page link that you want to replace the default link.
January 30, 2017 at 9:40 am #271775MarioPerfect. 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'; }
January 30, 2017 at 9:51 am #271780LeoStaffCustomer SupportMultiple 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'; }
January 30, 2017 at 10:01 am #271781TomLead DeveloperLead DeveloperYou can also use an array to shorten up the conditional a bit: https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
January 30, 2017 at 10:16 am #271797MarioThanks for your responses.
I meant the other side. Multiple pages with the same customized header linking this header to the osdemy web.
January 30, 2017 at 10:24 am #271808LeoStaffCustomer SupportSorry I’m a bit confused. You the logo of each page to link to a different site?
January 30, 2017 at 10:30 am #271818MarioI 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
January 30, 2017 at 10:33 am #271824TomLead DeveloperLead DeveloperThen 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; }
January 30, 2017 at 10:35 am #271827LeoStaffCustomer SupportAnd if you want all the “unofficial” headers to link to the same page, then you can simplified using this code:
https://generatepress.com/forums/topic/add-a-specific-link-in-a-logo-page-header/#post-271780or the array method Tom suggested: https://generatepress.com/forums/topic/add-a-specific-link-in-a-logo-page-header/#post-271781
February 4, 2017 at 3:41 am #274098MarioHello 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?
-
AuthorPosts
- You must be logged in to reply to this topic.