PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, May 15, 2022

[FIXED] How to display custom links in WordPress with wp_nav_menu?

 May 15, 2022     navigation, wordpress, wordpress-theming     No comments   

Issue

I'm creating an one-page custom theme. I'm struggling with a custom menu, because I want to display custom links.

I've registered menu in functions.php file

function register_my_menus() {
  register_nav_menus(
    array(
      'header-menu' => __( 'Header Menu' ),          
     )
   );
 }
 add_action( 'init', 'register_my_menus' );

Then, I've displayed in header.php file like this:

 <?php wp_nav_menu( array(
         'theme_location' => 'top-menu',
         'container' => 'ul',
         'menu_class'=> 'd-flex main-menu'
          ) );
    ?>

I've added custom classes for ul tag, and that is okay. Navigation works but just for pages. When I create a page, a link for that page shows up in navigation. However, after creating custom links they don't appear in navigation.

I'm searching the Stachoverflow for some quiet time, but without success. How to resolve a described issue? Do you have an idea?

Thank you for your time.


Solution

You have register header menu with header-menu key and trying to get it by key of top-menu which is not possible. You have to use the header-menu key to add and get a header menu. we have updated the code. you can use this code.

<?php 
wp_nav_menu( array(
     'theme_location' => 'header-menu',
     'container' => 'ul',
     'menu_class'=> 'd-flex main-menu'
    ) ); 
?>


Answered By - Dotsquares
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing