I'm trying to change the logo url of the site to "mywebsite/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' );
}
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' );
}
Share
Improve this question
asked Feb 16, 2017 at 15:56
PavanelloPavanello
451 gold badge2 silver badges4 bronze badges
4
|
8 Answers
Reset to default 3The 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.
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 );
}
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' );
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.
The easiest way is to add this jQuery code
jQuery(document).ready(function($){
$("a.logo-class").attr("href", "https://google.com");
});
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.
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' );
}
I wanted to do that as well, based on the _underscore theme. I couldn't find a ready-made way. So, i used web inspector to find the div containing the header logo.
It's in wp-includes/theme.php, line 1802 in my install.
I changed
'<div id="wp-custom-header" class="wp-custom-header">%s</div>'
to
'<div id="wp-custom-header" class="wp-custom-header"><a href="https://www.theURLToYourHomepa.ge">%s</a></div>'
and it works for all pages.
I'm not betting this is very orthodox, and i'm looking forward to hearing any comments about this.
header.php
that generates the URL to your question, and i will update my answer. – Johansson Commented Feb 16, 2017 at 18:03