WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. myladeybugg
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    i think a plugin robots meta will help you .

  3. myladeybugg
    Member
    Posted 1 year 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
    moderator
    Posted 1 year 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
    Member
    Posted 1 year ago #

    @keesiemeijer That code works perfectly!

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.