How To / No Plugins Necessary / PHP

Add a New Custom Menu to your WordPress Theme

wordpressphp2

It is actually really easy to add a new custom menu to your WordPress theme. Just copy the following code snippet(replacing “New Menu” and “new-menu” with the name of your custom menu) into your themes functions.php file or create your own plugin using my guide on the subject.

1
2
3
4
5
6
7
function register_my_menu() {

register_nav_menu('new-menu',__( 'New Menu' ));

}

add_action( 'init', 'register_my_menu' );

If you want to add more than one menu at a time, use this code snippet instead…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function register_my_menus() {

register_nav_menus(

array(

'new-menu' => __( 'New Menu' ),

'new-menu-2' => __( 'New Menu 2' ),

'new-menu-3' => __( 'New Menu 3' )

)

);

}

add_action( 'init', 'register_my_menus' );

Once you’ve done that, all you have to do is add the the following code snippet(replacing “new-menu” with the name of your custom menu & “new_menu_class” with whatever class you want to give it for styling purposes) wherever you want it to appear inside your themes php files(In most cases this will either be your themes header.php file or footer.php file).

1
<?php wp_nav_menu( array( 'theme_location' => 'new-menu', 'container_class' => 'new_menu_class' ) ); ?>

You might not need to include the <?php at the beginning of the snippet and the ?> depending on where within the code you try to insert this snippet.

Related Posts

Handy Code Snippets / How To / No Plugins Necessary / PHP / WooCommerce

Handy WooCommerce Store PHP Snippets

woocommerce-codesnippets

Here are some Handy WooCommerce Store PHP Snippets that you might find useful... Auto-Complete All WooCommerce Orders [cc lang="php"]...

Handy Code Snippets / How To / PHP / Plugins

List More Custom Field Names

ListMoreCustomFieldNames

First install & activate the List More Custom Field Names plugin. Then add the following code to your functions.php or your cust...

No comments

Leave a Reply