Monday, 21 September 2020

Wordpress Swap Primary Menu from Menu

Scenario:

I want to faciliate the user to choose from two different menus to be used as his/her primary menu.

I created two menus, and an Entry in both menus to switch to each other (Switch to B) (Switch to A).

The idea is that when a menu item is pressed, a wordpress function is called to switch the menu. Since I have already created the menus, they have specific IDs to choose from. All I want to hook specific function on clicking the (menu entries created in each menu) to swap the primary menu.

Questions

How can I call the code on a menu?

Do I need any modification for this code?

add_filter( 'arrange_by_A', 'arrange_by_B');

function arrange_by_A( $args ) {
    if( $args['theme_location'] == 'primary') {
        $args['menu'] = '45';
    }
    return $args;
}

function arrange_by_B( $args ) {

    if( $args['theme_location'] == 'primary') {
        $args['menu'] = '65';
    }
    return $args;
}


from Wordpress Swap Primary Menu from Menu

No comments:

Post a Comment