How To Register Menus And Use In Your Custom Theme In WordPress

Here we learn about how to register menus and use them in the custom theme.

WordPress allows creating custom menus.

Custom code copied and paste into your child theme’s functions.php file.

1. Registering Your Menu

If you can change your menu name or slug and whatever you want to set.

<?php
function register_menu() {
  register_nav_menu( 'homepage-footer-menu', __( 'Homepage Footer Menu' ) );
}
add_action( 'after_setup_theme', 'register_menu' );
?>

Now you can see the admin side navigation menu registered.

OUTPUT:

2. Display front side template

Below custom code copied and paste into the front side template.

<?php
if ( has_nav_menu( 'homepage-footer-menu' ) ) {
  /* if menu location 'primary-menu' exists then use custom menu */
  wp_nav_menu( array( 'theme_location' => 'homepage-footer-menu') ); 
}
?>

OUTPUT:

Submit a Comment

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

Subscribe

Select Categories