Saturday, May 8, 2021

Creating a Custom Menu in WordPress

Creating a Custom Navigation Menu in WordPress

Being able to add and remove links from a web site’s main navigation menu is a basic feature found in most website CMS’s. As of WordPress 3.0, there is built-in support for adding a navigation menu to any theme. Additionally, these navigation menus can be created and configured easily in the WordPress admin panel. WordPress custom menus must however be enabled for your current theme before you will be able to full use them.

Adding Support for Navigation Menus

You will have to add the PHP code provided below to your theme’s functions.php file (otherwise the custom menu option will not show up in the admin panel):

add_theme_support( ‘menus’ );

Adding a Navigation Menu to a WordPress Theme

Next you will want to tell WordPress where in your theme you want to place a menu. Generally, you would want to do this somewhere in your header.php file, where your theme’s header content is located. You may however add a custom menu to any part of your WordPress theme you think is best. Using the code provided below you can easily create one or even several spots for a custom menu to appear:

‘Top Menu’, ‘sort_column’ => ‘menu_order’, ‘container_class’ => ‘top-menu’ ) );?>

The above code is a simple call to the wp_nav_menu function which is built into the WordPress engine. The argument provided contains an array of attributes that may be used to configure the way a custom menu should be displayed at this location in the theme.

Advantages of Using WordPress Navigation Menus

As you can already probably see, there are many advantages to using the custom menu feature that is now provided in WordPress 3.0. Most website owners begin by adding a simple navigation menu to the top of their WordPress theme, however you can certainly add many more custom menus then just one. Another advantage, is the ability to add a custom menu as a widget to your sidebar. Again this feature is also built-in to the WordPress admin panel.

Speak Your Mind