0

I'm using this script to create a new custom menu on the fly and assign a page to it...

if ( !is_nav_menu( 'Header Menu' )) {
    $menu_id = wp_create_nav_menu( 'Header Menu' );
    $menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'),'menu-item-title' => 'Home', 'menu-item-status' => 'publish' );
    wp_update_nav_menu_item( $menu_id, 0, $menu );
}

However, what I'm stuck on is how to hook this menu up to my theme's "Menu Locations".

For example, my theme registers a menu location...

register_nav_menus(
array('header-menu' => __( 'Main Navigation Menu' ) )

);

How can I hook the "Header Menu" up to the "Main Navigation Menu" area via script?

ie, I can do this manually from the WordPress "Appearance > Menus" Manager and under "Theme Locations > Main Navigation Menu" I select "Header Menu" and click "Save". I'm trying to do this in script.

0

1 Answer 1

1

This question was answered here > https://wordpress.stackexchange.com/questions/14116/custom-nav-menu-is-created-with-default-pages-but-not-hooked-to-themes-custom-m

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.