How to target secondary menu and dynamically add an li to it

enter image description here

I’m making some good progress with managing my custom menus, but feel stuck on a specific issue. As the screenshot shows below, I have 2 menus I created in WP Admin. One is Primary Menu, and the other is Footer Menu…

I want to dynamically add an additional li to my Footer Menu.

This is where I am confused…Here is my initial attempt from my functions.php file…

    //Attempting to register my footer menu
    add_action( 'init', 'register_my_menu' );
    function register_my_menu() {
        register_nav_menu('footer-menu',__( 'Footer Menu','footer' ));
      }

   //Attempting to add something only to the footer menu
   add_filter('wp_nav_menu_items','ithub_footer_menu', 10, 2);
   function ithub_footer_menu( $items, $args ) {
       echo '<h2>'.$args->theme_location. '</h2>'; 
       if($args->theme_location == 'footer-menu')  {
           $items .=  '<li class="menu-item">Another slot</li>';
       }
       return $items;
   }

But its not appending anything to my footer menu from the browser. What I am doing wrong?

Thanks!

Read more here:: How to target secondary menu and dynamically add an li to it

Leave a Reply

Your email address will not be published. Required fields are marked *