WordPress #3: Add menu navbar on every page

Add pages

  • Pages
  • Add pages

Add menu

  • Appearance
  • Menus
  • Create a new menu
  • Name the menu and create
  • Check the page you want to add to menu/ navbar
  • Add to Menu
  • Menu Settings >> Primary Menu
  • Save Menu

Code

On functions.php, add,

function mytheme_register_nav_menus() {
    register_nav_menus( array(
        'primary' => __( 'Primary Menu', 'your-text-domain' ),
        'footer' => __( 'Footer Menu', 'your-text-domain' )
    )); 
}

On header.php, add,

<a class="navbar-brand" href="/"><?php wp_nav_menu( array( 'container_class' => 'main-nav', 'theme_location' => 'primary' ) );  ?></a>

On every page’s script, add to the top before <body>

<?php get_header();?>

The menu will pop up on the top of the page(s). Now it’s up to us how to design or relocate it by coding the script.


Comments

Leave a Reply

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