In this tutorial, our goal is to understand how menus can be used to organize content on a WordPress site. Menus are a crucial element of website design as they provide a way for visitors to navigate through your site.
By the end of this tutorial, you will learn:
Prerequisites: Basic understanding of WordPress and its dashboard. No coding skills required.
Menus in WordPress are navigational structures that allow you to organize your site content. They can be located in several places like the header (most common), footer, sidebar, or even inside content with a shortcode.
Appearance
> Menus
.Menu Name
box and click Create Menu
.You can add different types of items to your menu like pages, posts, custom links, and categories.
To add items:
Add to Menu
and they'll appear on the right-hand side.You can organize your menu items by dragging and dropping them. You can also create sub-items by dragging an item slightly to the right under another item.
Finally, you can display your menu on your site by assigning it to a menu location. Common locations include the header, footer, and sidebar. This varies based on your theme.
While menus are typically managed via the WordPress dashboard, there are instances where you might want to programmatically add, remove or change menu items. Here's an example of how you could do this in your theme's functions.php
file using PHP:
//Code to add a new menu item
function add_new_menu_items()
{
global $menu;
$menu[99] = array(
'My Custom Menu', //Menu title
'manage_options', //Capability
'my_custom_url', //Menu slug
'', //Function
'dashicons-admin-site', //Icon URL
99 //Position
);
}
add_action('admin_menu', 'add_new_menu_items');
In this code, we're adding a new menu item to the WordPress admin menu. We're using the admin_menu
action hook and a custom function to add our new menu item.
In this tutorial, we've learned how to create, customize, manage, and display menus in WordPress. We've also seen how to add items to your menus like pages, posts, categories, and custom URLs.
Next, you may want to learn more about WordPress theming to understand how different themes can affect your menu's locations and appearance. The WordPress Codex provides plenty of resources for this.
Solutions:
Appearance
> Menus
, create a new menu, add the required pages, and save.Tip: Experiment with different menu structures to see what works best for your site's structure and content.