• Home
  • About
    • Contact
  • WordPress
    • Plugins
    • Themes
    • iThemes
    • Builder
    • Tips and Tricks
  • Demos and Tutorials
    • Flexible Responsive Layouts using CSS in Builder

How to replace text links with icon links in WP 3 navigation menus

By Ronald
Sunday, July 11th, 2010

The new WordPress 3 navigation menus are an excellent tool to design your own menus, mixing pages, categories and custom links. iThemes created video tutorials on how to use the new WordPress navigation in Builder and Flexx theme. The following tutorial will show how you can replace the text links in the navigation menu with images. It can be used for any theme, on any WordPress site running WordPress 3+, but it is based on iThemes Flexx.

The Flexx theme, by design, uses graphical icons for the home page links, as can be seen in this theme demo. The WordPress 3 navigation won’t add these automatically.

In the following step by step guide, we will:

  • create 2 menus, one for pages, one for categories
  • create custom links to link to “home”
  • integrate the menus in the WordPress layout
  • figure out how we can address these links using CSS
  • add the necessary css to make it all work

Getting Started

Navigate to wp-dashboard > Appearance > Menus. If you have not created any menus, the theme locations will be empty (note, the Mobile Plugin navigation is not relevant for this tutorial).

WordPress 3 navigation theme locations

Create 2 menus, one for pages, one for categories

Create a “pages” menu (in this case pagesnav3, but call it whatever you want), and a “categories” menu (catsnav3), by selecting all pages and all categories.

WordPress 3 navigation page menu
WordPress 3 navigation categories menu

Create a custom link to your “home” page

Add the URL to your home page and create a custom link.

WordPress 3 navigation create custom link

Add the custom link to the page menu and to the categories menu. By default, a new custom link will be added to the end of the menu. Drag and drop the menu link to the top of the list of navigation items.

WordPress 3 navigation custom link home

Integrate the menus in the WordPress layout

WordPress 3 navigation add theme locations

Figure out how we can address these links using CSS

When you navigate to your site, you can now see that you have successfully added the home links, albeit still text links.

WordPress custom Home link

We need to find the unique menu item ID’s, assigned to each custom link. You can find instructions in a separate tutorial.

Add the necessary css to make it all work

Now that we know which ID (or ID’s, 165 and 166 in this case) we need to address in our CSS, we can add the appropriate CSS code to replace the text “home” with an image.

Add the following code to (the end of) your stylesheet.

#menu-item-165,
#menu-item-166 {
    text-indent: -9999px;
    width: 40px;
}

#menu-item-165 a,
#menu-item-166 a {
    background: #0b2300 url(images/menu-home-bg.gif) top center no-repeat !important;
}

#menu-item-165 a:hover,
#menu-item-166 a:hover {
    background: #0b2300 url(images/menu-home-active-bg.gif) top center no-repeat !important;
}
This code will make sure that:
  • the text “Home” is indented (or rather, outdented) way out of the visible area of your site for the menu items we added (menu-item-165 and menu-item-166)
  • the image “menu-home-bg.gif” is selected to show for the menu items we added
  • the image “menu-home-active-bg.gif” is selected to show for these menu items when hovering the mouse over them

Note, the images used are the same as used in the Flexx themes, and are expected to reside in a subfolder /images/ in your theme folder. For other themes, you may have to adjust the location, width, perhaps add padding or margins, and of course you can create your own images to achieve a similar effect. Here’s the end result:

icons replace text link in WordPress navigation
Categories : iThemes, Tips and Tricks, Wordpress
Tags : navigation menu, Wordpress

Comments

  1. Tweets that mention How to replace text links with icon links in WP 3 navigation menus :: van Weerd -- Topsy.com says:
    July 14, 2010 at 14:50

    [...] This post was mentioned on Twitter by ithemes. ithemes said: How to replace text links with icon links in WP 3 navigation menus – http://bit.ly/a9rK6M (via @vanweerd) [...]

    Reply
  2. Charley Hays says:
    December 5, 2010 at 15:38

    Hi Ronald,
    Thanks so much for this post. I am trying to do something very similar, I want to put 32×32 social media images in my nav bar.

    I have followed your steps and it has worked perfectly, except that the text I am replacing with the image has not shifted and is displaying over top of the image.

    I am using the latest version of builder, so any help you could provide would be greatly appreciated.

    Reply
    • Ronald says:
      December 15, 2010 at 23:26

      I think this has been resolved though the support forum, there was an issue with invalid css

      Reply
      • Pete says:
        November 26, 2011 at 01:07

        Hi Ronald,

        Where in the Forum has this been answered? I’ve been searching for an hour and cannot find the answer to how to get rid of the text displayed over top my images in my navigation bar.

        Thank you,

        Pete

        Reply
        • Ronald says:
          November 26, 2011 at 01:36

          Line 3 in the sample css code in the article makes sure that the text will not be on the screen.

          Reply
          • anthony says:
            November 26, 2011 at 03:30

            can you provide a link to your support forum where the css is corrected please?

  3. How to replace text links with icon links in WP 3 navigation menus … | UK SEO Company says:
    December 15, 2010 at 23:20

    [...] more here: How to replace text links with icon links in WP 3 navigation menus … Enjoy this post ? Tweet HERE or View original article here StumbleUpon twitter delicious [...]

    Reply
  4. How To Use Icon Links Instead Of Text Links On WP 3 Menus says:
    February 3, 2011 at 18:46

    [...] and attractive, just like this image for an example:So to get the icon links on your Menus, you can visit this page to read the whole tutorial.Good luck!You Might Like Theses Posts:Automatically Show Home Link On WP [...]

    Reply
  5. Renji says:
    February 11, 2011 at 08:09

    Hi Ronald, is it possible to add an icon to the left of text links? So that both text links and an icon is shown.

    Reply
    • Ronald says:
      February 11, 2011 at 14:28

      Hi, it sure is, check this out: http://www.ivorpadilla.net/cuztomizing-wordpress-custom-menu-icons/

      Reply
  6. Using Image Links in Wordpress Navigation Menus Instead Of Text Links | WordPress Stack Exchange Monitor says:
    February 16, 2011 at 17:33

    [...] http://vanweerd.com/how-to-replace-text-links-with-icon-links-in-wp-3-navigation-menus/ [...]

    Reply
  7. moose says:
    March 7, 2011 at 18:06

    Great tutorial.
    Only problem now, is when I am on a page, it isn’t identified in the navigation menu. (The Flexx theme demo is the same).

    Is there a way to have the hovered image show when on that particular page?

    If so that would be perfect.

    Reply
  8. budiono says:
    April 20, 2012 at 04:01

    hello, thanks for this very helpful tutorial :)

    Reply
  9. Le says:
    April 20, 2012 at 22:41

    I added the above code to my 2011 child theme but the 32 x 32 image doesn’t display. I know that you use the hybrid theme but could you help me use the correct css class and code?

    Reply
  10. Aha says:
    December 5, 2012 at 17:50

    Yeah It works! Thank you very much!

    Reply
  11. Tom says:
    January 28, 2013 at 11:56

    Hi, this is exactly what i want to do… but is there a 2013 alternative?? Cause text-indent seems not be suported anymore. It moves the whole of the screen – including the image :(

    Kind regards,
    Tom

    Reply
  12. Peter Grab says:
    May 8, 2013 at 16:52

    Hallo,

    i gave you the url of my test-site

    the theme ist a childtheme of twenty twelve

    i tried this the code i added to my style.css is:

    #menu-item-280 {
    text-indent: -9999px;
    width: 40px;
    }

    #menu-item-280 a {
    background: #0b2300 url(images/feed.png) top center no-repeat !important;
    }

    #menu-item-280 a:hover {
    background: #0b2300 url(images/feed-active.png) top center no-repeat !important;
    }

    after identifying number 280 as the id of the menu-entry i want to be represented by an icon instead of text – the result is, that there in the place, where the menu-item should be shown, quite on top left ob the menu-item “ABMELDEN”, nothing is to be seen at all

    so I got the additional css out and now the text ist here again

    any tip?

    Reply

Leave a Reply

Click here to cancel reply.