• Resolved kuchijumus

    (@kuchijumus)


    We are using local theme import with your plugin.

    Everything is perfect. After imported we want the menu automatically checked.( Primary Menu)

    //Our Theme Code
    register_nav_menus( array(
    ‘primary_menu’ => esc_html__( ‘Primary Menu’, ‘text-domain’ ),
    ) );

    Created Menu on Our Demo by name “Main Menu” and chcked “Primary Menu”

    What we need to implemented in this code.

    // Assign menus to their locations.
    $main_menu = get_term_by( ‘name’, ‘Main Menu’, ‘nav_menu’ );

    set_theme_mod( ‘nav_menu_locations’, array(
    ‘main-menu’ => $main_menu->term_id,
    )
    );

    • This topic was modified 8 years, 11 months ago by kuchijumus.
    • This topic was modified 8 years, 11 months ago by kuchijumus.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    you need to change the last part of the code to this:

    
    set_theme_mod( 'nav_menu_locations', array(
    'primary_menu' => $main_menu->term_id,
    )
    

    Have a nice day!

    Thread Starter kuchijumus

    (@kuchijumus)

    Can you give us example code? With our code?

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    here you go:

    
    function ocdi_after_import_setup() {
        // Assign menus to their locations.
        $main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
    
        set_theme_mod( 'nav_menu_locations', array(
                'primary_menu' => $main_menu->term_id,
            )
        );
    }
    add_action( 'pt-ocdi/after_import', 'ocdi_after_import_setup' );
    

    Take care!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Menu Save’ is closed to new replies.