If you want to add nofollow to WordPress menu links, then follow these simple steps. It is always good to maintain perfect link structure in WordPress website and I already wrote an article on how to add nofollow attribute to all external links. Coming to the WordPress menu, it many include both internal and external links. So if you want to add nofollow attribute to any particular link in WordPress menu then its possible my using inbuilt WordPress options.

Add nofollow to WordPress Menu Links
Any WordPress menu contains links to pages, categories, tags etc. If you are not indexing categories and tags, you can also add nofollow attribute to them. In this way link flow can be properly maintained across the whole blog. At present I’m using nofollow attribute to all category links in WPSquare WordPress menu. Lets see how to add nofollow to WordPress 3.0 menu links…
Method 1: Using WordPress 3.0 Menu Inbuilt Options
These options are available from WordPress 3.0 and works on latest version of WordPress also. Just follow these simple steps and nofollow tags will be added to selected menu items.
Step 1: Login to WordPress dashboard and go to Appearance > Menus.
Step 2: At the right side, you can see “screen options” tab, which on clicking will display a list of available options.

Step 3: In the Advanced Menu Properties section, select “Link Relation Ship” and a new field will be displayed on every menu link.

Step 4: Now, just type “nofollow” in Link Relationship field and save settings.

Step 5: Finally, rel=”nofollow” will be automatically added to that link in WordPress menu.
If you dont want to use inbuilt WordPress options and want to try your hands on code, then follow this alternative method. Before proceeding further, it is recommended to have a backup of WordPress Theme.
Method 2: Using Custom PHP Code in Functions File
To make this method work, you need to edit functions.php file in your WordPress theme and have to add the below code to it. Functioning of this code is clearly explained below, so please check it before adding this code to your theme.
/** Add nofollow to WordPress Menu Links */
add_filter('walker_nav_menu_start_el', 'add_nofollow_menu_links', 1, 4);
function add_nofollow_menu_links($item_output, $item, $depth, $args) {
$nofollow = array(15,16,17);
$location = '';
$menu = '';
if(
in_array($item->ID, $nofollow)
&& (!empty($location) && $args->theme_location == $location || empty($location))
&& (!empty($menu) && $args->menu == $menu || empty($menu))
){
$item_output = str_replace('<a ', '<a rel="nofollow" ', $item_output);
}
return $item_output;
}
Thanks to SEODenver for this useful code snippet.
Functionality of this code:
This is a simple PHP code that uses “Walker nav menu” filter to add nofollow attribute to menu links based on 3 parameters.
1. Menu Item ID
Each menu item got an unique ID and it can be easily find by checking the page source of WordPress website. Generally, menu item ID’s will be in this format menu-item-15 where “15″ is the ID of that particular item.

$nofollow = array(15,16,17);
In the above code snippet, just enter all menu ID’s inside the array separated by comma and nofollow tag will be added to those particular menu items only.
2. Menu Location
This completely depends on the theme you are using. For default WordPress themes like Twenty Ten or Twenty Eleven, one WordPress menu is available and is named as “Primary menu”.

$location = 'Primary Menu';
Just enter the menu location name in the above code and nofollow tag will be added to links in that particular menu.
3. Menu Name
Finally, it works based on the name of the menu also. You can name WordPress menus as “primary-menu” or “secondary-menu” based on the structure of the theme you are using.

$menu = 'primary-menu';
I want to add nofollow tag to links in primary-menu and hence included the same in this code. You can use any of these 3 methods based on the requirement and they works like a charm.
Conclusion
If you are serious about SEO and all then consider adding nofollow to WordPress menu links. It is always good to pass the link juice to valuable links and the default dofollow attribute will do the work for you. Coming to the flip side, never allow low quality links getting indexed into Google or other search engines. Finally, its completely upto you and this whole thing depends on your blogging strategies.
If you find these article useful, then consider dropping a comment here. If you think adding nofollow to menu links is not a perfect method then lets start a healthy debate here.


How to Remove Date from Meta Description in Search Results
How to Import and Export Content in WordPress
jQuery Lazy Load Images in WordPress without Plugin
Display Blog Posts in Two Columns using Genesis Grid Loop
How to Automatically Convert keywords to Affiliate Links in WordPress
How to Backup your WordPress Blog to Google Drive
I love the first method, easy and not technically difficult. Thank you for providing code too and extended explanations.
The first method is very easy In my opinion. BTW I have a doubt, Why to nofollow internal links ?
nice thank you very much. this post is very useful and valuable
thanks for the info..its help me lot as i new in blogging
Hey man!
I was searching for this all over the place. I always got some troubles with wordpress , your site looks like a great resource for further reference.
thanks a bunch
keep ‘em coming brother
Akos
It’s so cool. You helped me saving a lot of time. Great article! Thanks man.
The same for me… I found the first method the simplest. Thanks!
Great Tutorial. First method is easy.