I would like to change the logo redirection when clicked. Right now when you click on the logo, the user is redirected to the homepage but I want it to redirect to another site. How do I do this?
5 comments
Comments are closed.
I would like to change the logo redirection when clicked. Right now when you click on the logo, the user is redirected to the homepage but I want it to redirect to another site. How do I do this?
Comments are closed.
I agree with Stu Mileham. Another way to implement what you are asking for would be to use JavaScript / jQuery.
Save the following code to a .js file (eg. pageRedirect.js, let’s say placed in a js folder inside your theme’s root folder):
To make the previous code work, you would have to select somehow the page logo via jQuery.
On the previous code this is achived via $(‘#pageLogo’) since I have made the assumption that your logo has an id with the value pageLogo.
Of course, to enable your theme to use this pageRedirect.js file, you have to enqueue it by placing the following code to your theme’s functions.php file:
Code Explanation:
If you don’t have the option to change the link from admin then you will have to edit your theme’s header.php file (most likely, depends on how the theme is built though).
Many themes have a tag similar to the following:
You would need to change this to:
I’ve added the target tag to open the site in a new window, this is my personal preference when re-directing to a different site but it’s optional.
Your theme files might look very different to this, it’s impossible to know for sure without seeing some code, but this should give you an idea.
Also be aware that your changes could be overwritten by a theme update. This can be avoided by creating a child theme.
https://codex.wordpress.org/Child_Themes
Depends on your theme
Some theme creators gives you the possibility to change the link from admin
Some theme creators just believe that clicking the logo you need to go on homepage – so you need to edit the theme
Depending upon the theme you are using, you can try one of the following options.
header.php
. Do an inspect element on your logo and see the html code surrounding the logo file, If the code is directly present inheader.php
, your task is simple. Just change the code to update the URL, instead of reading it fromhome_url()
. Something like<a href="<?php echo home_url();?>">
will need to be replaced with<a href="https://www.example.com">
The other option to look for is
get_custom_logo
. Some themes get the logo code from this function. You can apply a filter to change thehome_url
just before this method is called in your theme and then remove filter afterwards. Or else you can copy the code from wordpress and update it with a differently named function sayget_custom_link_logo
infunctions.php
then where’ver your theme is usingget_custom_logo
you can useget_custom_link_logo
instead of that.function get_custom_link_logo ( $blog_id = 0 ) {
This might not cover all the use cases, but you get the idea. Depending upon the theme you’ll have a similar solution for your case. The important thing to figure out which case you fall under will be to identify the code where html for your logo is getting added.
header.php
is a good starting point.Use this javascript in the header or footer of your theme:
i am assuming that site-logo is the class name of your LOGO.