I use sparkling theme. Previously I have had custom link in main menu. but the visitor needed to leave the web-page and move to the link page. So I needed to change like that it would open a new tab for the linked page.
Now it works like that the current (my web site - load linked page) plus it opnes also in a new tab the same page.
I tried to take off the option “open link in a new tab”, but it still keep the same work.
Here is the website - www.jaakkoteppo.fi, and the problimatic menu is “Kuvat”.
I would be very happy if someone can help me to solve it.
Thank you very much for the answer and link. I see the solution there, but could you plese tell what should I do? Should I change the code some some specific file or reinstale the theme?
You can just try changing the functions sparkling_add_top_level_menu_url and sparkling_make_top_level_menu_clickable code with the following updated code.
/**
* Adds the URL to the top level navigation menu item
*/
function sparkling_add_top_level_menu_url( $atts, $item, $args ){
if ( !wp_is_mobile() && isset($args->has_children) && $args->has_children ) {
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'sparkling_add_top_level_menu_url', 99, 3 );
/**
* Makes the top level navigation menu item clickable
*/
function sparkling_make_top_level_menu_clickable(){
if ( !wp_is_mobile() ) { ?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ){
if ( $( window ).width() >= 767 ){
$( '.navbar-nav > li.menu-item > a' ).click( function(){
if( $( this ).attr('target') !== '_blank' ){
window.location = $( this ).attr( 'href' );
}else{
var win = window.open($( this ).attr( 'href' ), '_blank');
win.focus();
}
});
}
});
</script>
<?php }
}
add_action('wp_footer', 'sparkling_make_top_level_menu_clickable', 1);
Thank you for the instructions, but it did not change the situation with menu. I made changes in those functions. But the menu is still opening several new tabs.
I visited your site to test and it seems working fine for me on clicking on the menu KUVAT it opens the page https://www.instagram.com/jaakkoteppovirallinen/ in new tab and the current page doesn’t change at all. It only opens one new tab and not many.
If it’s not working like this for you then try clearing your browser cache or using different browser.
In which browser you tested the page? I have tried all possible it works well with every except FireFox. I checked the link on different computers. onmy own computer I clean the cache and in firefox it is stillthe same.
This is not happening on my site using latest version of theme.
To help us keep support thread separates could you please create your own thread for your question here https://colorlibsupport.com/c/sparkling/ instead of replying on others thread as it makes the thread messy and hard to read.
If you want to you can also add reference of this thread in your newly created thread.
We would be more than happy to help you on your new thread.