WordPress – Custom Menu

Custom menus are a great options for WordPress. A menu is basically a list of links. This list of links can appear anywhere in your theme. You can customize the links that appear in the list via the admin panel.

A theme may contain as many custom menus as you care to add. Each can be customized through the admin panel. Custom menus can appear anywhere in your site you care to place them.

To get started create a function.php file in your theme folder.  Next add a <?php ?> tag to your functions.php file. Your functions.php should contain one <?php ?> tag and all of the custom php code should go between the <?php and ?>.

Now add the code to generate a new custom menu. Add the following inside the <?php and ?>:

// Notify WordPress that you want to run a function when the page initializes
add_action( 'init', 'register_my_menus' );

// Here's the function
function register_my_menus() {
   // Call this function to register a new menu
   // Declare a slug-name and a display name for the new menu
      array('header-menu' => __( 'Header Menu' ) )

The first line tells WordPress to call on the function resgister_my_menus when the page initializes. The register_my_menus function is defined below. This functions calls on register_nav_menus, which is defined by WordPress. This function receives an Array describing the menu to create.The menu gets two names. A slug name which is used in code to refer to the menu. The other is a display name which is used when the name appears in a page.

The __() function used to wrap the display name, as in __(‘Header Menu’) is a special function used translate your page in to other languages. See the codex for more information. This function is not required but is good practice to include.

For more info refer to the codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu

Leave a Reply

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