Why put nofollow attributes in menu structure? In a nutshell it all boils down to relevance. Every link on your particular web page should have to do with the subject that it is about. In this article I am talking about the nofollow attribute. However if you look above at my menu I have several things that have nothing to do with the nofollow attribute.
What is a NoFollow attribute?
A nofollow attribute is a code that is put into an anchor link. It lets search engines know that when they come to spider and index your page that you have links on the page that have nothing to do with the subject matter on that particular page. The no follow code attribute looks like this.<a href="a1websitepro.com" rel="nofollow">Anchor Text</a>
How do I add nofollow in my WordPress Menu Structure?
Its a little hard to locate so I will show you in pictures below how to do it. First off make sure that you are using a "custom menu structure" in WordPress. Here is a little video that will help you set up a custom menu in WordPress if you don't know how. https://youtu.be/eymlPBekrPw One you have your custom menu set up in WordPress follow these steps to make your menu items contain the nofollow attribute.- Go to Appearance > Menu
- Open your "Screen Options" in the top right side of the screen.
- Make sure under "Show Advanced Menu Properties" that "Link Relationship (XFN)" is checked.
- Open each of your menu items and add the nofollow text in each of the links.
- Now when you go to the front of your website you will have nofollow on your menu items. Now when the search engines spider your page you will not get penalized for linking to irrelevant content on your webpage. :-)
A WordPress Function to Make all Links nofollow
I do not encourage all links to be made nofollow in a website. If you are linking to relevant content then you should follow those links through. This not only gives your visitor good information but also gives you link juice for providing good relevant links to your visitors. However if you have a large website and do not want to go back and make all of your links nofollow here is a WordPress function that will take care of all the links in your wordpress and make a nofollow attribute to them. You would put this in your functions.php file in your theme.add_filter( 'the_content', 'cn_nf_url_parse'); function cn_nf_url_parse( $content ) { $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>"; if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) { if( !empty($matches) ) { $srcUrl = get_option('home'); for ($i=0; $i < count($matches); $i++) { $tag = $matches[$i][0]; $tag2 = $matches[$i][0]; $url = $matches[$i][0]; $noFollow = ''; $pattern = '/target\s*=\s*"\s*_blank\s*"/'; preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE); if( count($match) < 1 ) $noFollow .= ' target="_blank" '; $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/'; preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE); if( count($match) < 1 ) $noFollow .= ' rel="nofollow" '; $pos = strpos($url,$srcUrl); if ($pos === false) { $tag = rtrim ($tag,'>'); $tag .= $noFollow.'>'; $content = str_replace($tag2,$tag,$content); } } } } $content = str_replace(']]>', ']]>', $content); return $content; }