Have you ever wanted to use icons/images instead of plain text for Login/Register links on a WordPress blog? Thankfully WordPress allows a down to bone customization so you could say that almost everything is possible. Our technique is simply achieved by creating two functions and adding them to your theme’s function.php file.

To replace Log in/Log Out text with a desired image, simply copy the code below and make your functions.php file ready for editing (through WordPress Theme Editor or FTP),

//Image instead of text for the "Login & Log Out" links
function ax_login() {
$before = '<li class="axLinks">';
$after = '</li>';
$theme_url = get_bloginfo('template_url');
if ( ! is_user_logged_in() )
$link = $before . '<a href="' . wp_login_url() . '">' . '<img src="' . $theme_url . '/images/login.png" alt="Log in" />' . '</a>' . $after;
else
$link = $before . '<a href="' . wp_logout_url() . '">' . '<img src="' . $theme_url . '/images/logout.png" alt="Log Out" />' . '</a>' . $after;
echo apply_filters('loginout', $link);
}

Paste the code you copied and then submit/save the file. Pick two icons you like (the size it’s up to you to decide but names are relative to the code, see: login.png, logout.png) and upload them to your theme images folder. Reload your WP site and ta-da!!! There you see two new shiny icons you didn’t have before. This code applies to any situation, whether you do have or not the Meta Widget active.

What just happened?

This function will override the output of loginout filter, it requires you to have wp_loginout(); somewhere on  your theme where you want to show your login icon. You can even style it using CSS by adding the .axLinks{ } class to your theme’s style.css file, and then manipulate it as you desire. Here’s a small CSS block which gives only basic directions.

.axLinks li, a, img{
background-color: transparent;
list-style: none;
text-decoration: none;
border: 0; }

The same treatment can be applied to the register filter as well, with just some small necessary changes, of course a new functions needs to be created only to avoid confusion. Below you can find the code for Register/Site Admin links. Follow the same steps as with the function above.

//Image instead of text for the "Register & Site Admin" links
function ax_register() {
$before = '<li class="axLinks">';
$after = '</li>';
$theme_url = get_bloginfo('template_url');
if ( ! is_user_logged_in() ) {
if ( get_option('users_can_register') )
$link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . '<img src="' . $theme_url . '/images/register.png" alt="Register" />' . '</a>' . $after;
} else {
$link = $before . '<a href="' . admin_url() . '">' . '<img src="' .$theme_url . '/images/site_admin.png" alt="Site Admin" />' . '</a>' . $after;
}
echo apply_filters('register', $link);
}

This function will override the output of register filter, it requires you to have wp_register(); somewhere on  your theme, more precisely wherever you want your register/site admin icon. Now if you don’t have any pre-chosen icons, there are numerous choices out there.

This little modification has been tried and proven to work up to WordPress.2.7.1 and is intended to save you from editing the core, instead creating two easy-to-customize functions that can be delivered with your theme. If you encounter any potential problems feel free to ask by commenting below.  Cheers!

This was a guest post by Arian Xhezairi, a WordPress manic, web developer and Twitter user (follow him here!). You can also check out his site, iTechnologize.net. If you have WordPress knowledge and are interested in writing a post for WordPress Hacks, please contact us.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Tweet This | Digg This | Stumble it | Add to Del.icio.us | | Print This

Arian Xhezairi

Arian Xhezairi is a 22 years old blogger, web developer and technology enthusiast. Passionated about Web Technologies Arian started developing since 2004. Started blogging in late 2007 and been a podcaster at The Vista Forums since then. He is a Cadet Officer at the Military University in Prishtina, and currently at the end of his fourth and last year. He runs his own advertising agency since 2007.

There Are 11 Responses So Far »

  1. p@r@noid says:

    Thanks for the new hack :)

  2. Nice hack. It is very useful for people who use WordPress as membership system.

  3. wayne says:

    really nice hack…thanx arian…

  4. Dean Saliba says:

    Thank you for this hack. I’m going to use it on my blogs as I think images will look better than the default text links.

  5. Dev says:

    Nice hack @kyle and thanks for the good post @Arian Xhezairi. This is an awesome hack. But where is the demo of this hack. I think you need to show how login page is look like after this hack.

  6. Wow, what a nice hack to use.

    It surely makes the normal links look boring now if you use images instead, thanks for the info.

  7. Guys, I’m gal you all welcomed this hack.

    @Dev, let me clarify a misunderstanding. This hack does not change the login page, but it only lets you use images for your links. :)

    Cheers.

  8. Correction: I’m glad*
    sorry :shy-face:

  9. Ha, that’s pretty sweet. Thanks a ton for the tutorial! :)

  10. Dieta says:

    The idea seems so simple yet the results are so great it’s surprising. Thanks for posting that hack – I’m definitely gonna use it one day (I need som nice pics first ;)

  11. Mike Wagan says:

    Nice hack. It is very useful for people who use WordPress as membership system.

Trackbacks/Pingbacks »

Leave a Reply