Navigation Menus
Learn to add links to the navigation menu and create dynamic menus.
Navigation links
We can make the navigation links in the header and footer dynamic using the site_url()
method. This method is used to retrieve the URL of the WordPress site.
site_url()
The site_url
method returns the base URL of the WordPress installation that is set in the WordPress General Settings. It is used for creating links within a WordPress site or when retrieving resources such as images or scripts. The site_url
function also has an optional parameter that allows us to specify a path to a specific file or page within the website. For example, site_url('/about-us/')
creates a link to the About Us page on the site (as long as it is located in the root directory of the site).
We will use echo
with this function so that the output is received by the browser.
Let’s start with the header. Open the header.php
file and locate <div class="nav-items">
tag. The code is reproduced below:
Get hands-on with 1400+ tech skills courses.