How To: Add Images to WordPress Login/Register links

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 available.

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.

  • Leave a Comment
  • WordPress Launches WordPress.tv

    Over the weekend I noticed that WordPress has launched a sweet new visual resource for their blogging software, which can be found at WordPress.tv. As you would probably guess by the domain extension, WordPress.tv will provide video tutorials for both WordPress.org and WordPress.com installations.

    If you look at it now, you’ll find a lot of extremely basic tutorials for people new to WordPress, but one cool thing is you can submit requests to see future WordPress video tutorials.  I would imagine over time you’ll start to find a lot more advanced WordPress tutorials.

    Some other cool things about WordPress.tv:

    WordPress.tv is also now the place to find all that awesome WordCamp footage that was floating around the web without a home. See the presentations you missed and get a peek at behind-the-scenes action. We call it WordCampTV.

    You’ll also find slideshows of presentations made by Automattic employees and other WordPress gurus, plus interviews I’ve done with the media and fellow bloggers.

    I hope you’ll consider WordPress.tv not just a support resource, but also a place to hang out and keep up with all the geeky goodness going on in the WordPress community. Tune in regularly for fresh content and updates to the WordPress.tv blog. Lots more is on the way.

  • Leave a Comment
  • Make an Apple.com Style Breadcrumb for Your WordPress Blog

    Breadcrumbs, as has been said before on WPHacks, are very useful, both for your SEO and reader’s navigation. In other words, there is no reason why you shouldn’t have them on your site.

    There are a number of breadcrumb plugins you could use, but with a bit of WordPress code, you can avoid this. If you use sub-categories, then this will only display the name of the sub category.

    A typical breadcrumb is something like this:

    Home >> [Category] >> [Post Title]

    WordPress can very easily do this – to get the name of the category the post is in, all you need is

    <?php the_category(); ?>

    Then, to display the post title, the code you need is

    <?php the_title(); ?>

    So our final code, with some arrows added in is:

    <a href="/">Home</a> &raquo;  <?php the_category('   '); ?>   &raquo; <?php the_title(); ?>

    So now that you’ve got your breadcrumb sorted, you can take this one step further and spice it up a bit. For the next part, we’re going to be using the code from a tutorial at Janko at Warp Speed, and with this code, we’re going to turn our breadcrumb into something that looks like the ones you see on Apple.com!

    First, download the html version here, and open it in a your web editor (ie Notepad, Dreamweaver etc). Scroll down until you find <ul id=”breadcrumb”>. This is where we’re going to start editing. All you need to do is copy and paste the following code:

    <ul id="breadcrumb">
    <li><a href="/" title="Home"><img src="/images/home.png" alt="Home" class="home" /></a></li>
    <li><?php the_category(', ') ?></li>
    <li><?php the_title(); ?></li>
    </ul>

    This is basically the same code as we had above, just putting into a list. Make sure you upload the home.png file to /images/, and while you’re at it, upload the other images.

    Next thing we need to do is the CSS. Go into your style.css and paste the following:

    #breadcrumb {
    font: 11px Arial, Helvetica, sans-serif;
    height:30px;
    line-height:30px;
    color:#9b9b9b;
    border:solid 1px #cacaca;
    width:100%;
    overflow:hidden;
    margin:0px;
    padding:0px;
    }
    #breadcrumb li {
    list-style-type:none;
    float:left;
    padding-left:10px;
    }
    #breadcrumb a {
    height:30px;
    display:block;
    background-image:url('/images/bc_separator.png');
    background-repeat:no-repeat;
    background-position:right;
    padding-right: 15px;
    text-decoration: none;
    color:#000;
    }
    .home {
    border:none;
    margin: 8px 0px;
    }
    #breadcrumb a:hover {
    color:#35acc5;
    }

    Once you’ve done that, then you’re done! If you copy the code from the source file (which you should), then make sure you change the url of the images.

  • Leave a Comment
  • How to: Using Thumbnails in your Sidebar “Recent Post” Listing

    On the WP Recipes forum, a guy just asked me how I managed to insert thumbnails on the recent post widget located on the sidebar of my blog Cats Who Code. That’s a lot simpler than it seems.

    If you’d like to see a live demo of this tutorial, just click here.

    1) – Make sure you’re using a custom field in your posts, with the thumbnail url.

    There’s a lot of tutorials available online to add a custom field to your pots. This one is good in my opinion, so you should read it if you don’t know how to define a custom field.

    2) – Download the required plugins

    In order to customize your recent posts widget, you have to download the Recent Posts plugin by Sebastian Schmieg.

    You’ll also need to download and install the Post-Plugin Library, which contains all the php functions needed by the Recent Posts plugin.

    3) – Upload and activate the plugins

    Once you downloaded the plugin and the library, unzip the files and upload it to your wp-content/plugins directory. Then, login to your WordPress dashboard, Go to “Plugins” and activate both the library and the Recent Posts plugin.

    4) – Configure the plugin

    After having the plugin and the library uploaded and activated, you have to configure the options so you’ll be able to display the post thumbnail on your sidebar.

    To do so, login to your WordPress dashboard and navigate to “Settings”, “Recent Posts”.
    On “General”, you can tell the plugin how many posts to be displayed, if it should display posts and pages or only posts, and a lot more.

    Once you configured the “General” options to fits your needs, go to the “Output” options. In order to display your custom field thumbnail on your sidebar, you have to enter a bit of html as well as the special parameter to embed the custom field.

    Here’s the code that I entered:

    <li><img src="{custom:Image}" width="48" height="48" alt="" />{link}
    <div class="clear"></div>
    </li>

    The special parameter {custom:Image} tells the plugin to embed the Image custom field. Don’t forget to replace Image with the name of your custom field!

    5) – Add the widget to your sidebar

    Simply go to “Design”, “Widgets” and add the Recent Posts + widget to your sidebar. Visit your blog, your thumbs are showing in the sidebar along with your recent posts!

  • Leave a Comment
  • How to: Upgrade your WordPress Blog in a Minute via SSH

    Having to upgrade your WordPress install every time a new version is released is necessary, but also very boring. If you have a SSH access to your server, here’s a very quick way to upgrade your WordPress install.

    This is probably the most important step of this whole tutorial: always backup your WP Database and files. This tutorial have been tested, however I won’t be held responsible for any kind of data loss.

    Once done, you can connect to your server by using SSH. On Mac and Linux platform you can use the Terminal, on Windows I recommend using Putty.

    Get the latest WordPress version available:

    wget http://wordpress.org/latest.tar.gz

    Uncompress it:

    tar xfz latest.tar.gz

    Delete the wp-admin and wp-includes directories:

    rm -rf ./wp-includes/
    rm -rf ./wp-admin/

    Go to the wordpress directory:

    cd wordpress/

    Now, it’s time to copy the downloaded files to your existing WP install, by overwriting old files:

    cp -rpf -f * ../

    Once done, come back to the WordPress directory and remove the downloaded files:

    cd ..
    rm -rf ./wordpress/
    rm -f latest.tar.gz

    Visit your blog and upgrade the database (if needed). That’s all, your blog is now up to date and the whole process didn’t took more than a minute or two!

  • Leave a Comment
  • How To: Building a Google Custom Search Engine (GCSE) into Your WordPress Blog

    Over the holiday weekend I decided to spend some time cleaning up a few of my websites and while doing this, I ended up installing Google’s Custom Search Engine on a couple of my WordPress blogs (as of this post I haven’t done this on WP Hacks yet, but will probably end up doing so here as well).

    For people wondering how to easily install Google’s Custom Search Engine (GCSE) on their WordPress blog, here are two resources I recommend:

    • Build Your Google Custom Search Engine – The first step is to actually create your Google Custom Search Engine.   The post by Maki over at Dosh Dosh does a GREAT job of explaining how to do this.   Towards the end Maki explains how to actually integrate it into your WordPress blog, but rather than go through all those steps, you’ll want to instead check out the second step.
    • Integrate your Google Custom Search Engine into WordPress – Once you’ve built your custom search engine, head over to this post and figure out a quick and easy way to integrate it into your WordPress blog.   This method ONLY requires you to alter the searchform.php and search.php files (which most themes come with), so it is really easy.

    Why Use Google’s Custom Search Engine?

    With the current setup of the WordPress search engine, posts are displayed with the most recent post first based upon the search term.   Using Google’s Custom Search Engine, it will use Google’s search algorithm to display your posts with the most relevant post on top and you can actually integrate it into your WordPress blog, so it looks natural.   Using this also allows you to display Google AdSense ads, which can earn you money on some blogs.

    The main downside with this method is that Google has to actually index the post before it will appear in your blog’s search results, but that won’t be a problem for most blogs.  It will just add a small delay before posts appear in your search results.

  • Leave a Comment
  • Top 5 WordPress Navigation Menu Tutorials

    Navigation menu is a really important part of a website, both visually and functionally. Though, I noticed that most blogs use a really simple navigation menu. A simple menu can be good sometimes, but if you’re looking for something more sophisticated, I’m pretty sure you’re going to enjoy this list.

    Here’s 5 really cool tutorials to help you create a stunning navigation for your WordPress blog.

    Creating Two-Tiered Conditional Navigation in WordPress


    Which WordPress user doesn’t know Darren Hoyt, the creator the free magazine theme Mimbo Magazine ? In this great tutorial, Darren explains how to create a professional two-tiered navigation menu. Source

    How To: Making a Categories Drop-Down Menu


    This was my first post on Hack WordPress, and seems like you guys enjoyed it. In this tutorial, I explain how to create a navigation bar with a category drop-drown menu. Source

    WordPress: “Magazine style” Horizontal dropdown menu


    One of my last tutorials, published on my blog CatsWhoCode. This how-to explain how you can create an horizontal dropdown menu. Source

    Using Sliding Doors with WordPress Navigation

    This sliding doors CSS hack allows you to create sophisticated tabs for your navigation bar. Sadly, WordPress core functions wp_list_pages() and wp_list_categories() don’t allow you to add the required span tag to use this technique.
    This tutorial will show you how to bypass this limitation by using a hack, and then you’ll be ready to enjoy sliding-doors for your WordPress navigation! Source

    Any other navigation tutorial that should be in the list? Leave us a comment below!

  • Leave a Comment