How to Open Menu Items in a New Window or Tab in WordPress Easily

Did you know that you can open a menu item in a new tab or window? This is especially useful if you want to keep visitors on your site while they browse the menu-linked content.

Table of Contents

What is a WordPress Menu, and Why Would You Want to Open a New Tab?

Method #1

WordPress menus are a necessary component of any WordPress website. They make it simple to organize and navigate your website’s pages. Did you know that you can open a menu item in a new tab or window?

This is especially useful if you want to keep visitors on your site while they browse the menu-linked content. We’ll review WordPress menus and why you might want to open a menu item in a new tab or window in this article.

Following a few simple steps, you can easily open menu items in a new window or tab in WordPress.

 

First, go to your WordPress dashboard and select the Appearance tab. Choose Menus and then navigate to the menu item you want to open in a new window or tab.

Then, click the arrow icon next to the menu item to expand the options. Select the “Open link in a new tab” option under the Link Target section.

You can also use the Advanced Menu Properties to make your link’s target _blank.

Once you’ve made your decision, remember to save your changes. When you click on a menu item, it will open in a new window or tab.

It’s that easy! Your menu items can easily open in new tabs or windows, giving your website visitors a better user experience.

 

Method #2

You can also add the following code to your theme’s functions.php file to open all external links in a new tab:

 

				
					function open_external_links_in_new_tab() {
echo '<script type="text/javascript">';
echo 'var links = document.getElementsByTagName("a");';
echo 'for (var i = 0; i < links.length; i++) {';
echo 'if (links[i].href.indexOf(location.host) == -1) {';
echo 'links[i].target = "_blank";';
echo '}';
echo '}';
echo '</script>';
}
add_action('wp_footer', 'open_external_links_in_new_tab');

				
			

All external links will open in a new tab, keeping your visitors on your site while they explore external resources.

You can easily open menu items in a new window or tab in WordPress by following these simple steps, providing a better user experience for your website visitors.

 

Subscribe to Our Newsletter

Stay up-to-date with WordPress news, tips, and exclusive offers by subscribing to our newsletter.

*By subscribing, you are signing up to receive our emails and can unsubscribe at any time.

More Posts

Related Posts