How to make menu link open in new tab wordpress

There are a few ways to make a menu link open in a new tab in WordPress. Here are a few methods:

Method 1: Using the target attribute

You can add the target attribute to the link in your menu item. To do this:

  1. Log in to your WordPress dashboard.
  2. Go to Appearance > Menus.
  3. Click on the menu item you want to edit.
  4. In the "Navigation Label" field, add the following code: target="_blank" (without quotes) at the end of the link URL.
  5. Save the changes.

For example, if your menu item URL is http://example.com/about, you would add target="_blank" to the end of the URL, like this: http://example.com/about target="_blank".

Method 2: Using a plugin

You can use a plugin like "WP Menu Open in New Tab" or "Menu Link Target" to achieve this. These plugins allow you to easily add the target attribute to your menu links.

  1. Install and activate the plugin.
  2. Go to the plugin settings page (usually found under Settings > Menu Open in New Tab or similar).
  3. Configure the plugin to add the target attribute to your menu links.
  4. Save the changes.

Method 3: Using a theme function

If you have a custom theme or a theme that allows you to add custom functions, you can use a theme function to add the target attribute to your menu links.

  1. Add the following code to your theme's functions.php file:
    function add_target_to_menu_links($items) {
     foreach ($items as $item) {
         if (!empty($item->url)) {
             $item->url.= ' target="_blank"';
         }
     }
     return $items;
    }
    add_filter('wp_nav_menu_items', 'add_target_to_menu_links');
  2. Save the changes to your functions.php file.
  3. Go to Appearance > Menus and refresh the page. Your menu links should now open in a new tab.

Note: The above code is just an example and may need to be modified to fit your specific theme and menu setup.