Change logo url link

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' );
}

Topic logo urls links Wordpress

Category Web


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.


The easiest way is to add this jQuery code

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

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.


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' );

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 );
}

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.


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' );
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.