WordPress

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:

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago