Conditional menu items

Here is one of the methods to manage menu items according to the name of active page.
In Appearance ->Menus->Screen Options enable  “CSS Classes”. Thus in every menu item settings appears input field “CSS Classes (optional)”. In the apropriate menu item write in class name (“vip” in our case) into this field.
Then we create .css file manage_menu.css. In manage_menu.css we have:

#top-menu .vip {
    display: none;
}

Now we enqueue this style file in dependence upon the name of active page:

function my_menu_control( $hook ) {
    $pagename = get_query_var('pagename');
    
    _F9J_register_style( 'my_manage_menu', get_template_directory_uri() . '/css/manage_menu.css', array(), '1.0.0', 'all' );
    if ( 'my-page-name' != $pagename ) {
        _F9J_enqueue_style( 'my_manage_menu' );
    }
     else { return; }
}

add_action( '_F9J_enqueue_scripts', 'my_menu_control' );

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *