2

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' );
}
  • 1
    Hi, are you trying to change the url of the homepage logo? or the login panel? – Jack Johansson Feb 16 '17 at 16:03
  • The homepage logo – Pavanello Feb 16 '17 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 '17 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. – Jack Johansson Feb 16 '17 at 18:03
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.

  • 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 '17 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. – Jack Johansson Feb 16 '17 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 );
}
  • Good function in case he wants to change every single bloginfo('url') in his website so that the old URL becomes unreachable! – Jack Johansson Feb 16 '17 at 18:13
  • good point. changed answer so that it works only when custom_logo() and home_url() are called in conjunction – Nathan Johnson Feb 16 '17 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

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' );
}
  • using the get_page_by_path as you suggested above did not work! – Pavanello Feb 16 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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