Custom link in menu BUG

Hello,

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.

BR
Damira

and in mobile devices it works normally. I checked on several computers it doubles the page.

help is very needed! Does someone face this problem before?

Hi Damira,

Sorry to hear of the problem you are having.

It’s the known issue which is resolved in the github version of the theme which you can get from here https://github.com/puikinsh/Sparkling

We will also update the theme version on WordPress repository soon.

Best Regards,
Movin

Dear Movin,

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?

Dear Movin,

I downloaded the new sparkling-master.zip and installed in my wordpress. However, it shows that I need to rebuild again everything on my web pages.

Is there any other solution? Can I make some changes in code? or anything, that I do not need to build the whole site again.

Thank you in advance.

Hi Damira,

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);

Best Regards,
Movin

Dear Movin,

could you still direct me in which document I should do the code change of those functions you mentioned?

I am very sorry for million of questions!

Best regards,
Damira

Those functions are in the sparkling theme file /inc/extras.php

Dear Movin,

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.

What I can still do?

Bestregards,
Damira

Dear Movin,

now the page works with menu in a way that it opens custom link in meny to two new tabs. Is it still fixable?

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.

Hi!

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.

Could you try in FF?

I look forward to getting your answer.

Best regards,
Damira

I am using chrome browser and could confirm the issue using firefox browser.

You can resolve this issue by using the following code instead of above previously shared 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' );
            }
        });
      }
    });
  </script>
<?php }
}
add_action('wp_footer', 'sparkling_make_top_level_menu_clickable', 1);

Dear Movin!

Thank you very much! It works now!!!

Uhuuu!

Have a great day! Thank you for your work and patience!

Best regards,
Damira

You are most welcome here :slight_smile:

Hi,

I think the newest update fixed the bug but another issue appeared.

Every time I click the menu link set to target="_blank", it will also open a blank pop-out window which Chrome will automatically block it by default.

I think this is not a normal situation the function intended to be, thanks :stuck_out_tongue:

Cheers,
Clement

Hi Clement,

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.

Thanks,
Movin