3

I'm trying to change the logo url of the site to "mywebsite.com/side2", but it is not working, can anyone tell me where is the error in the code below?

add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {

return home_url( 'side2' );
}
4
  • 1
    Hi, are you trying to change the url of the homepage logo? or the login panel?
    – Johansson
    Feb 16, 2017 at 16:03
  • The homepage logo
    – Pavanello
    Feb 16, 2017 at 16:42
  • @JackJohansson I found out what is wrong, the login_headerurl function is for the login page and what I want is for the main logo of the site, do you know what is the function for the url of the main logo of the site? You were right!
    – Pavanello
    Feb 16, 2017 at 17:20
  • Yes i just posted an answer about that. Copy the part of your header.php that generates the URL to your question, and i will update my answer.
    – Johansson
    Feb 16, 2017 at 18:03

7 Answers 7

3

The login_headerurl filter is for changing the logo url of login page, according to the Codex.

To change the logo URL of your homepage, you will have to look into your theme's header.php file. You logo and it's link are included there. Depending on your theme, they way that your URL is generated may be different.

Access your header.php file from Appearance > Edit in the admin panel, and search for the line containing the logo. There, you can change it to whatever you want.

2
  • Ok, but I need to change the link in function.php, because the link will vary according to the user profile. The above script is only the part that changes the url.
    – Pavanello
    Feb 16, 2017 at 16:54
  • You can change it based on user in headers.php too. If the theme developer is simply using a bloginfo(url) to output the URL, there is no way to change it using functions.php, unless you change the ENTIRE bloginfo() functions, or any other function used.
    – Johansson
    Feb 16, 2017 at 17:05
3

If the theme author is using bloginfo('url') to output the url, then you can do the following.

bloginfo('url') is a wrapper for echo get_bloginfo('url') which is a wrapper for home_url() which in turn is a wrapper for get_home_url(). The code for that function is available here.

As can be seen, there is a filter available at the end of the function that you can use to change the value of the home url.

Edited so that the filters only fire for the home_url and custom_logo filters are both called.

add_filter( 'home_url', 'wpse_106269_home_url', 10, 4 );
function wpse_106269_home_url( $url, $path, $orig_scheme, $blog_id ) {
  add_filter( 'custom_logo', 'wpse_106269_custom_logo', 10, 2 );
}

function wpse_106269_custom_logo( $html, $blog_id ) {
  //* Remove the filter
  remove_filter( 'custom_logo', 'wpse_106269_custom_logo', 10, 2 );

  //* Use str_replace() to change link
  return str_replace( $old_url, $new_url, $html );
}
2
  • Good function in case he wants to change every single bloginfo('url') in his website so that the old URL becomes unreachable!
    – Johansson
    Feb 16, 2017 at 18:13
  • good point. changed answer so that it works only when custom_logo() and home_url() are called in conjunction Feb 16, 2017 at 19:39
2

You can Use this function to change the Logo url in Wordpress.

Simple add this code in function.php file

//changing the url on the logo to redirect them
function mb_login_url() {  return home_url(); }
add_filter( 'login_headerurl', 'mb_login_url' );

// changing the alt text on the logo to show your site name
function mb_login_title() { return get_option( 'blogname' ); }
add_filter( 'login_headertitle', 'mb_login_title' );

To change the Logo in Admin side login page

function my_login_logo_one() { 
?> 
<style type="text/css"> 
body.login div#login h1 a {
background-image: url(http://sitetitle.com/logo-1.png);  
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo_one' );
1

In case anyone else if facing the same issue, I created the plugin SMNTCS Custom Logo Link a while ago, which works with all themes that have 100.000+ active installations. If the theme that you're using is not among those themes, simply create an issue on https://github.com/nielslange/smntcs-custom-logo-link/issues and I'm happy to extend the plugin.

0

The easiest way is to add this jQuery code

jQuery(document).ready(function($){  
        $("a.logo-class").attr("href", "https://google.com");
});
0
0

I ended up taking the following Javascript-based approach which worked for my purposes. I am using the theme from https://theme.co/x. I installed the Insert Headers and Footers plugin and then added the following Javascript (Footer section):

<script>
    document.getElementsByClassName('x-brand')[0].setAttribute("href", "https://example.com");
</script>

You will need to change the 'x-brand' to point to the class of the logo href element specific for the given theme you are using.

2
  • I think it would be better to fix the page though. I'd be nervous the browser would start loading the old image, or there might be brief a layout jump if you don't have height and width attributes on them. There must be a way to change it in your theme.
    – Rup
    Aug 27, 2021 at 9:41
  • Agreed. It's not the ideal solution but I spent about an hour looking for a way to change it in the theme, including looking through the theme's code, and couldn't find a way. Aug 30, 2021 at 15:17
-1

You can use the get_page_by_path as follows:

add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {

  return get_page_by_path( 'side2' );
}
1
  • using the get_page_by_path as you suggested above did not work!
    – Pavanello
    Feb 16, 2017 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.