• Resolved myideasforsite

    (@myideasforsite)


    Hello. I try to add hook to functions.php that will remove cycle link on current page, but it does not work with mega menu plugin

    function nav_menu_no_link($no_link){
    $gg_mk = '!<li(.*?)class="(.*?)current-menu-item(.*?)"><a(.*?)>(.*?)</a>!si';
    $dd_mk = '<li$1class="\\2current-menu-item\\3">$5';
    return preg_replace($gg_mk, $dd_mk, $no_link );
    }
    add_filter('wp_nav_menu', 'nav_menu_no_link');

    I also try to change current-menu-item class to mega-current-menu-item

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi myideasforsite,

    I am curious to know why you want to remove that class? If you simply want to stop current menu items from being highlighted, you can uncheck “Highlight current item” in the menu theme.

    Otherwise this code looks like it should work:

    https://wpexplorer-themes.com/total/snippets/remove-current-menu-parent-class-wordpress-menu/

    The filter name would need to be changed from ‘nav_menu_css_class’ to ‘mega_ nav_menu_css_class’.

    Regards,
    Tom

    Thread Starter myideasforsite

    (@myideasforsite)

    no, I want to remove link from current page in menu, I dont want to change class or highlight current item
    <li id="menu-item-2201" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2124 current_page_item menu-item-2201">Contacts</li>
    As u see link <a… dissapeared if link has current_page_item class
    I need it for seo

    Thread Starter myideasforsite

    (@myideasforsite)

    Its called Redundant or Cycle Links. The presence of such links on the site badly affects the position in the search engine

    Plugin Author megamenu

    (@megamenu)

    Hi myideasforsite,

    I have not heard that before – are you sure that is the case for menu systems? I have checked amazon, ebay, even google itself and they do not remove the link for the current page.

    That aside, does your code work whilst MMM is disabled? That would be the first step.

    Regards,
    Tom

    Plugin Author megamenu

    (@megamenu)

    Hi myideasforsite,

    I have checked the filter itself works with Max Mega Menu, and it does:

    function nav_menu_no_link($no_link){
    	return "hello";
    }
    add_filter('wp_nav_menu', 'nav_menu_no_link');

    So there must be an issue with your regex that you would need to investigate.

    Regards,
    Tom

    Thread Starter myideasforsite

    (@myideasforsite)

    everything ok. Its not plugin, my mistake. Right function with regex

    function nav_menu_no_link1($no_link){
    	$newstr = preg_replace('/(<li.+?mega-current-menu-item.+?)(href=".+?")(.+?)/m','$1',$no_link);	
    	return $newstr;
    }
    add_filter('wp_nav_menu', 'nav_menu_no_link1');
    Plugin Author megamenu

    (@megamenu)

    Hi myideasforsite,

    Thanks for the update, glad to hear you got it working ??

    Regards,
    Tom

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add hook to menu’ is closed to new replies.