Please vote on the question and any answers you find useful by clicking on the UP arrow on the left hand side of the question or answer.
As with many others who are now viewing this post, I have been reading various blogs, forums, and discussion groups to learn and improve my wordpress skills. Over the past 12 months I have been on a mission to substitute my use of plugins by adding code to my
functions.php
file instead. While I completely agree that plugins are very useful in many situations my experience proved that in 90% of usage cases although a plugin might exist, actually utilizing it could create unnecessary complications and compatibility issues. Additionally in a great deal of cases such plugins added menus and other admin elements which I don't want or need.More often than not I have found that by analyzing the code of plugins I was able to strip out the piece of code I wanted and hard code it into my
functions.php
. This provided me with the exact functionality I needed without having to include unnecessary elements.So, the purpose of this post is my attempt to engage you, the reader/admin/developer, to share with me and other here any code bits which you find useful and have added to your theme's
function.php
file to extend or enhance WordPress without utilizing a plugin.When you submit a response here please kindly give each code bit a title, let us know if with what version of wordpress you know its compatible with, include whatever description you feel best describes its function and (if applicable) include a link to the original plugin or source where you found the information.
I am looking forward to all your responses and will of course continually add my own new finds whenever I find them.
ANSWER:-
Tested on: WordPress 3.0.1
This code will allow you to easily modify the WordPress Login page Logo as well as the href link and title text of this logo.
add_filter( 'login_headerurl', 'namespace_login_headerurl' );
/**
* Replaces the login header logo URL
*
* @param $url
*/
function namespace_login_headerurl( $url ) {
$url = home_url( '/' );
return $url;
}
add_filter( 'login_headertitle', 'namespace_login_headertitle' );
/**
* Replaces the login header logo title
*
* @param $title
*/
function namespace_login_headertitle( $title ) {
$title = get_bloginfo( 'name' );
return $title;
}
add_action( 'login_head', 'namespace_login_style' );
/**
* Replaces the login header logo
*/
function namespace_login_style() {
echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>';
}
EDIT: If you want to use the site logo to replace the login logo, you can use the following to dynamically pull that information (tested on WP3.5):
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 '<style>'.PHP_EOL;
echo '.login h1 a {'.PHP_EOL;
echo ' background-image: url( '; header_image(); echo ' ) !important; '.PHP_EOL;
echo ' width: '.$width.'px !important;'.PHP_EOL;
echo ' height: '.$height.'px !important;'.PHP_EOL;
echo ' background-size: '.$width.'px '.$height.'px !important;'.PHP_EOL;
echo '}'.PHP_EOL;
echo '</style>'.PHP_EOL;
}
0 comments:
Post a Comment