The Blog

Create a Social Icons Navigation with Integrated Search Bar

social-icons-tutorial

With a little bit of custom CSS and icons downloaded off the web, you can create a fabulous menu bar anywhere on your site using the Headway Navigation Block – which means you can align it however you want, include a search bar, and use a WordPress menu with it!

Two Styles & Approaches

We can either add a navigation menu that includes text links to our social profiles alongside helpful visual icons, or we can opt to display the icons only – no text. Regardless, we’ll start by creating a WordPress Menu under Appearance -> Menus. In your menu, add a custom URL menu item for each of your social media profiles (i.e. the url to your Twitter account would be something like http://twitter.com/headwaythemes, and if you have a vanity URL for Facebook it would be like https://www.facebook.com/HeadwayThemes).   Label each icon appropriately (i.e. Twitter, Facebook) – don’t leave the labels blank, it’s not necessary and not screen-reader/Google friendly.

Once you’ve added your menu items, click on the Screen Options tab on the top right of your screen. This will bring up the panel to add/remove options for your menu items. We need to ensure that the option for custom CSS classes is available, so check that box.

menuoptions

 

Now, when you edit a menu item, you can add a custom class to each one. We’ll add a class related to the menu item’s social network. For example, let’s give the Twitter menu item a class of twitter, the Facebook item a class of facebook, etc.

You should also find a social media icon set you like and upload the appropriate images to the WordPress Media Library.

(See this article on the WordPress Codex for information on how to create a menu and menu items)

Icons Only

The CSS to display the icons alone uses a CSS technique called Image Replacement.  The latest & greatest Image Replacement technique is outlined on Nicolas Gallagher’s site and you can read about it there.

You’ll use a snippet of CSS like this for each social media menu item. Replace the unique class (remember twitter and facebook ?) with the right class for each item, and replace the image path to reflect the URL for the correct icon in the WordPress Media Library.

My CSS here below is specific to the navigation block in Headway; as a rule your CSS should be just specific enough to target your element, but not overly specific. In our case, however, we need to be very specific in order to properly override the CSS that Headway applies from your settings in the Visual Editor.  So our Twitter link with a class of twitter will have CSS like this:

.block-type-navigation ul.menu li.twitter a {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background: url(test.png); /* This should be the URL of your icon */
width: 64px; /* This should be the width of your icon */
height: 64px; /* This should be the height of your icon */
}

Now rinse and repeat for each icon! The menu label will disappear and your icon will appear. Make sure that your navigation block is tall enough to accomodate your icons as well.

Icons + Text

This method has a slightly different approach; we want the link to have an icon next to the label, rather than replacing the text with the icon.  Your CSS for each item will look similar to this (and again – change the .twitter to .facebook, .pinterest, etc based on the classes you assigned in the first part of this tutorial!)

.block-type-navigation ul.menu li.twitter a {
background: url(test.png) no-repeat left center; /* This should be the URL of your icon */
padding-left: 64px; /* This should be the width of your icon */
height: 64px; /* This should be the height of your icon */
}

That’s It!

You’ve got some sexy navigation going on, now! Stay tuned; next Tuesday we’ll be posting a tutorial on how to make your navigation menu “stick” to the top of the page as you scroll down!

Spread the word!

By adding a comment below, you agree to abide by our comment policy.

10 comments
shellyp
shellyp

I'm trying to set up my nav bar for icons only, but I keep getting an error message in css for the line where I enter the image url. Can you show me an example of the icon only code with a url in place so I can see why mine isn't working? Thanks.

caitlinheadway
caitlinheadway

 @shellyp what sort of error exactly? If the image can't be found, just make sure you have the image right. If you can't get it working without a full image URL, then use the full link, like url("http://mydomain.com/myimage.jpg") -- the image should be visible if you copy/paste the link into your browser. 

Latest blog post: Sign Up | Headway Toolbox

shellyp
shellyp

 @caitlinheadway It looks like more of an alert actually and says the code is "overqualified". It prompts me to remove the "ul" before menu and the "li" before twitter in line 1 of the code.

 

However, whether I remove those parts or not, the icon still isn't loading. The logo is visible when I past the URL in my browser, so I'm thinking that maybe I'm putting the CSS in the wrong place? I'm very new to all this, so bear with me!

 

I'm in Wordpress 3.5.1. I'm placing your snippet in Appearance --> Edit CSS --> then pasting your code in the window that appears. Am I way off here?

shellyp
shellyp

 @caitlinheadway Thanks Caitlin. I'm making progress, but a few things are still wonky. Any chance you can peek at my site and see if it's clear to you what I'm doing wrong? (www.everyland.com). 

The twitter icon looks to be doubled up, and the black background of my nav bar behind the icon is gone.

Website Designing Services in India
Website Designing Services in India like.author.displayName 1 Like

Yes, adding social signal buttons is vital for the blog to get a good social reach as well, you can either add only icons or images of the various social networks or you can add both icon and text displaying the names of the social network buttons on the website.

It helps to get a good visitors to the site. Thanks for the codes.