WordPress Login – Customize logo and link

WordPress Login - Customize logo and linkThe login page of a WordPress installation can also be adjusted relatively quickly and conveniently using a few filters. With the following snippets, both the logo and the link behind the logo/header can be adjusted.

The code can either be inserted in the functions.php of a theme or even better as part of your own plugin. The plugin variant has the advantage that the changes to the login page are retained even if the theme is changed.

WordPress Login – Replace Logo

The following snippet is used to set your own logo on the WordPress login page:

add_action( ‘login_head’, ‘namespace_login_style’ ); function namespace_login_style() { echo ‘

‘; }

add_action( ‘login_head’, ‘namespace_login_style’ );

function namespace_login_style() {

echo ‘

‘;

}

The fourth line of the snippet is the path to the logo file. Of course, a complete URL can also be specified here instead of composing the path. This could then look like this:

add_action( ‘login_head’, ‘namespace_login_style’ ); function namespace_login_style() { echo ‘

‘; }

add_action( ‘login_head’, ‘namespace_login_style’ );

function namespace_login_style() {

echo ‘

‘;

}

WordPress Login – Change Link and Title

The following two WordPress filters are used to change the link and the title attribute behind the logo on the WordPress login page. The first filter adjusts the link or the url, the second the title attribute of the logo.

add_filter( ‘login_headerurl’, ‘namespace_login_headerurl’ ); function namespace_login_headerurl( $url ) { $url = home_url( ‘/’ ); return $url; }

add_filter( ‘login_headerurl’, ‘namespace_login_headerurl’ );

function namespace_login_headerurl( $url ) {

$url = home_url( ‘/’ );

return $url;

}

Instead of home_url(‘/’) for reading out the blog URL in line 3, any other URL can also be specified.

add_filter( ‘login_headertitle’, ‘namespace_login_headertitle’ ); function namespace_login_headertitle( $title ) { $title = get_bloginfo( ‘name’ ); return $title; }

add_filter( ‘login_headertitle’, ‘namespace_login_headertitle’ );

function namespace_login_headertitle( $title ) {

$title = get_bloginfo( ‘name’ );

return $title;

}

Instead of get_bloginfo( ‘name’ ) in line 3, any string can also be output.

Replace login logo with site logo

If the blog has its own header image, then this can also be used automatically for the login page. To do this, the namespaceloginstyle() function from the example above must be replaced with the following function:

function namespace_login_style() { if( function_exists(‘get_custom_header’) ){ $width = get_custom_header()->width; $height = get_custom_header()->height; } else { $width = HEADER_IMAGE_WIDTH; $height = HEADER_IMAGE_HEIGHT; } echo ‘

‘.PHP_EOL; }

1

2

3

4

5

6

7

8th

9

10

11

12

13

14

15

16

17

function namespace_login_style() {

if( function_exists(‘get_custom_header’) ){

$width = get_custom_header()->width;

$height = get_custom_header()->height;

} else {

$width = HEADER_IMAGE_WIDTH;

$height = HEADER_IMAGE_HEIGHT;

}

echo ‘

‘.PHP_EOL;

}

The WordPress Club

Previous post WordPress login and administration via HTTPS
WordPress Hide-and-Seek: Why there is no point in obfuscating the use of WordPress Next post WordPress Hide-and-Seek: Why there is no point in obfuscating the use of WordPress