Ad

 How to Create WordPress Pages and Add Them to Your Navigation Bar


Before we dive into the steps, let's clarify a common misconception:

Who to create: This part doesn't apply. You, the website owner or administrator, are the one who will create the pages.

WordPress pages:These are static pages on your website, like an "About Us" or "Contact" page.

Navigation bar: This is the horizontal or vertical menu at the top or side of your website where visitors can navigate to different pages.

Creating WordPress Pages and Displaying Themes in the Navigation Bar


To display WordPress pages in your theme's navigation bar, you'll primarily interact with two areas:


1. Creating the Pages: This involves using the WordPress dashboard to create the content you want to display.

2. Adding Pages to the Navigation Menu:This involves using the WordPress menu management system to specify which pages should appear in your navigation bar.

3. Displaying the Menu in Your Theme: This involves using PHP code (specifically, the `wp_nav_menu()` function) in your theme's header or navigation template to output the menu.


Here's a step-by-step guide to creating and displaying a single-item menu in WordPress:


1. Create Your WordPress Pages


1. Log in to your WordPress dashboard.
2. Go to Pages -> Add New .
3. Create the page you want to display in your menu. Give it a title and content.
4. Click  Publish.

2. Enable the Menu Option in WordPress


1. Go to Appearance. If you don't see the Menu option, proceed to the next step.

 3. Register the Navigation Menu


1. Open your theme's directory and create a new file named `functions.php` if it doesn't already exist.
2. Add the following code to `functions.php`:

    php code 

    <?php
    register_nav_menus( array(
        'primary-menu' => 'Top menu'
    ) );
    ?>

    

4. Refresh the WordPress Dashboard


1. Go to your WordPress dashboard and refresh the page.
2. You should now see the  Menu option under Appearance.


 5. Create a Menu with One Item


1. Navigate to Appearance -> Menus .
2. Click  Create a new menu.
3. Give your menu a name (e.g., "Single Item Menu").
4. Check the box next to the page you want to be the only item in your menu.
5. Click  Save Menu .



 6. Display the Menu in Your Theme


1. Open your theme's directory and find `header.php`.
2. Remove the old navigation code if it exists.
3. Add the following PHP code to the desired location within `header.php`:

    php code

    <?php
    wp_nav_menu( array(
   'theme_location'=>'primary-menu', 
        'menu_id' => 'primary-menu',
        'container' => 'nav',
        'container_class' => 'navbar-nav'
    ) );
    ?>
    

 Final Steps


1. Save and upload `header.php` to your server.
2. Refresh your WordPress site to see the new menu in action.





Post a Comment

Previous Post Next Post