php-wordpressHow to create a menu in WordPress using PHP?
Creating a menu in WordPress using PHP is a simple process. The following example code will create a menu in WordPress:
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'nav-menu'
) );
?>
This code will output a menu with the class nav-menu
:
<ul class="nav-menu">
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 2</a></li>
<li><a href="#">Menu Item 3</a></li>
</ul>
The code consists of the following parts:
wp_nav_menu()
: This is the main function used to create a menu in WordPress.theme_location
: This is the name of the menu location.container
: This is a boolean value that determines whether a container element should be added around the menu.menu_class
: This is the class that will be added to the menu.
For more information, please refer to the following links:
More of Php Wordpress
- How to disable PHP warnings in WordPress?
- How to use get_header in WordPress using PHP?
- How to increase the upload limit in WordPress using PHP?
- How to get the current URL in WordPress using PHP?
- How to add a shortcode in WordPress?
- How to send an email using PHP in WordPress?
- How to create a snippet in WordPress using PHP?
- How to run an SQL query in WordPress using PHP?
- How to use the WordPress REST API with PHP?
- How to redirect to another page in WordPress using PHP?
See more codes...