Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:24:25+00:00 2026-06-14T19:24:25+00:00

I have a WordPress menu that has a few menu items I added through

  • 0

I have a WordPress menu that has a few menu items I added through the standard (drag and drop) WordPress admin menu feature. Recently I had to add another item to the menu that generates a dynamic href link. I achieved that using the following code in my functions.php file:

//add my profile menu item dynmacially to the members menu (generate
user name based on current user logged in)

add_filter(‘wp_nav_menu_items’,’add_profilelink_in_menu’, 10, 2);

function add_profilelink_in_menu( $items, $args ) {

if( $args->theme_location == 'secondary')  {

 global $current_user;            
       //converts user id to username           
       $user_info = get_userdata($current_user->ID);

$items .='<li id="menu-item-2091" class="menu-item menu-item-2091">
 <a href="https://www.mysite.com/members/' . $user_info->user_login .'">Profile</a>
 </li>';

  }
  return $items;  

}

My problem is that this menu item is added to the end of the menu and the regular WordPress Menu classes such as ‘current-menu-item’ don’t get applied to this item. Is there a way for me to control the position of where this menu item is added to (For example: add this item after the first two items?)

and how can I get WordPress to treat this dynamically generated menu item as a regular menu item and have it add all the classes that it adds the other menu items (created through the WordPress menu feature)?

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:24:27+00:00Added an answer on June 14, 2026 at 7:24 pm

    Here’s the logic that you can base using jquery

      //suppose your menu is this
      <ul id="secondary_nav">
        <li id="li_unique_id_1"><a href="">menu 1</a></li>
        <li id="li_unique_id_2"><a href="">menu 2</a></li>
        <li id="li_unique_id_4"><a href="">menu 4</a></li>
    </ul>
    
     //the jquery workaround
     //place this in your footer
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
    <script type='text/javascript'>
    $(function(){
        <?php
         global $current_user;            
         //converts user id to username           
         $user_info = get_userdata($current_user->ID);
        ?>
        $("<li id='menu-item-2091' class='menu-item menu-item-209'><a href='https://www.mysite.com/members/<?php echo $user_info->user_login; ?>'>Profile</a></li>").insertAfter("#secondary_nav #li_unique_id_2");     
    });   
    </script>
    

    You can also use insertBefore function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drop-down menu that are dynamically added through WordPress. It looks like
Have created a custom navigation menu in wordpress that has some pages and some
I have a wordpress theme that has a build in shortcode for creating an
I have a horizontal menu for wordpress site and the menu items are categories.
I have written a function for a multilevel wordpress menu, but I'd like it
I am using WordPress I have put an extra container in the navigation menu.
I am working with wordpress and I have to display a menu based on
I'm working on a solution that has two applications 1) Wordpress based CRM (frontend)
This is the website i´m working on: http://canal.es/wordpress/ The problem I have is that,
I have seen scripts that have a menu fixed to the top of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.