Archived topic
Add link to header image?
14 replies · Started by _blank on December 30, 2014
Site is http://3de.48c.myftpupload.com/
WordPress 4.1
GeneratePress 1.2.4
I've added a Header image to my site (so that it appears on all pages) using the Background Images Add-on that came with my purchase of GP Premium. I need to have this header image link to a page within the site. Is this possible?
I also notice that the header image is not responsive. Is there a better way to add a header image and have it be responsive and linkable?
Hi Art,
For a header image like that, you're better of using the "Customize > Header Content" section and upload it as a logo.
Let me know if that works :)
OK, that works! TY
btw…
I added css…
/* tighten space around header image if image is placed using Customize > Header Content */
.inside-header {
padding: 0px;
}
and edited the link in the theme's header.php to make the header image link to a page in the site other than the home page. (be aware that GeneratePress theme updates may overwrite the edit done to header.php)
If there's a better way to do the link change, please let me know.
You would be better off using a child theme, and copying the header.php file over to your child theme folder. This way, your changes won't be lost when you update.
However, you'll also miss out on any changes I make to header.php.
I just went ahead and added a filter to the href of the logo, so once 1.2.5 is released, you can use a snippet of PHP to change the URL without modifying any core files.
It would work like this (Note: This will not work until GeneratePress 1.2.5 is released).
add_filter( 'generate_logo_href','generate_add_custom_logo_href' );
function generate_add_custom_logo_href()
{
return 'http://yourcustomlogohref.com';
}
Hi Tom,
somehow I did not manage to REMOVE any link from the header image.
How do I go about that?
Best wishes,
Markus
To remove the link, I would remove the logo from the Customizer.
Then using GP Hooks, add your logo using the "Before Header Content" hook.
<div class="site-logo">
<img class="header-image" src="THE URL TO YOUR LOGO" alt="YOUR WEBSITE NAME" />
</div>
Thanks! It worked, of course ;)
All best,
Markus
You're welcome :)
Where should I insert this code within the header.php?
It would work like this (Note: This will not work until GeneratePress 1.2.5 is released).
function generate_add_custom_logo_href()
{
return 'http://yourcustomlogohref.com';
}
This should help: https://generatepress.com/knowledgebase/adding-php-functions/
Hi Tom,
I created a plugin using your code with my href page name:
<?php
function generate_add_custom_logo_href()
{return 'http://www.actonrecovery.com/rachel-shaw-bio/';}
?>
When clicking on the header logo image, it returns me to my home page. What did I do wrong?
Hi there,
I just adjusted the code: https://generatepress.com/forums/topic/add-link-to-header-image/#post-60248
Let me know if it works or not :)
Thanks Tom,
The additional line worked
You're welcome :)
