• vicn1222

    (@vicn1222)


    Hello,

    I am brand new to WordPress.

    I just download 6.1.1 and try to learn wordpress. All settings are default by the installation. The scheme is TT3.

    In the admin dashboard, I see a “Header navigation”, I can interactively create some menus without problem.

    I try to get this navigation object programatically and see if I can add some menus into it in php. However, all methods return false or null using wp functions below.

    $locations = get_nav_menu_locations();
    var_dump( $locations );

    $nav = wp_get_nav_menu_object( “Header navigation” );
    var_dump( $nav );

    $nav = wp_get_nav_menu_object( “” );
    var_dump( $nav );

    $locations = get_theme_mod( ‘nav_menu_locations’ );
    var_dump( $locations );

    What do I do wrong? Thank you for your help.

     

    • This topic was modified 2 years ago by vicn1222.
    • This topic was modified 2 years ago by vicn1222.
    • This topic was modified 2 years ago by James Huff.
Viewing 1 replies (of 1 total)
  • Hi @vicn1222,

    Thank you for reaching out. The Twenty Twenty-Three (TT3) theme is a Block Theme, which behaves differently than what’s called a “Classic Theme”. The linked documentation explains these differences.

    Since the navigation in TT3 is built out of blocks and does not register menu locations, many of the PHP functions you noted will not work the same way or at all.

    That said, there are likely alternative “block-first” ways you could try, such as creating a custom block or block variation. Would you be able to share what you are trying to accomplish?

    Best,
    Nick

Viewing 1 replies (of 1 total)
  • The topic ‘How to get header’s nav object programmatically?’ is closed to new replies.