[resolved] Make Links No Follow On Text and Menu Widgets (5 posts)

  1. myladeybugg
    Posted 2 years ago #

    I am looking to make all text widget and menu widget links no follow. I looked in default-widgets.php, but couldn't find anything in there.

    I believe there are plugins that will do this, but I am not looking to make all the links on my blogs as no follow.

    I am running multisite with buddypress.

  2. andy2grant
    Posted 2 years ago #

    i think a plugin robots meta will help you .

  3. myladeybugg
    Posted 2 years ago #

    Thanks for the plugin @andy2grant. I'll take a look at it. I am going to need to apply this to all blogs on my network, and not do it blog by blog.

    That's why I am looking more for a code change.

  4. keesiemeijer
    Posted 2 years ago #

    Try it with this in your theme's functions.php:

    add_filter( 'wp_nav_menu_objects', 'menu_rel_nofollow', 10, 2 );
    function menu_rel_nofollow( $items, $args ) {
      foreach ($items as $item) {
        $item->xfn = 'nofollow';
      return $items;
    add_filter('widget_text', 'text_rel_nofollow');
    function text_rel_nofollow($content) {
      return stripslashes(wp_rel_nofollow($content));

    This will add the nofollow to all menu item links (in or outside a widget) and to links in the widget text.

  5. myladeybugg
    Posted 2 years ago #

    @keesiemeijer That code works perfectly!

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.