• Resolved Generosus

    (@generosus)


    Good Day,

    I would like to reorder your plugin’s admin toolbar sub-menu links (i.e., quicklinks) in alphabetical order (or custom order) – both in the backend and frontend.

    Can you guys provide a code snippet that will allow me to do that? It would be very useful for all of us.

    Useful Tip: I tried to modify the code snippet provided here, but couldn’t get it to work.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @generosus,
    ?
    Thank you for contacting Rank Math support.
    ?
    Unfortunately, there is no way to sort the admin bar menu items.
    ?
    Please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter Generosus

    (@generosus)

    Respectfully, I disagree. Other plugin developers have been able to accomplish that.

    Can you kindly elevate this topic to your chief developer for a second look? It may take a little extra time, but I’m sure it can be done.

    Until then, please do not close this topic as resolved.

    Thank you.

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @generosus,

    Please use the following filter to sort our plugin’s admin bar menu alphabetically:

    add_filter( 'wp_before_admin_bar_render', function( $items ) {
    global $wp_admin_bar;
    // Get all current menu items
    $admin_bar_items = $wp_admin_bar->get_nodes();

    // Filter the items that start with 'rank-math'
    $rank_math_items = array_filter($admin_bar_items, function($item) {
    return strpos($item->id, 'rank-math') === 0;
    });

    // Sort the filtered items alphabetically by title
    usort($rank_math_items, function($a, $b) {
    return strcmp($a->title, $b->title);
    });

    // Remove the original rank-math items from the admin bar
    foreach ($rank_math_items as $item) {
    $wp_admin_bar->remove_menu($item->id);
    }

    // Re-add the rank-math items in alphabetical order
    foreach ($rank_math_items as $item) {
    $wp_admin_bar->add_menu((array) $item);
    }
    } );

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter Generosus

    (@generosus)

    Perfect! Thank you so much.

    Perhaps you guys can add the above to your documentation?

    Cheers ??

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @generosus,
    ?
    We are super happy that this resolved your issue. No other user has requested this. If we receive more requests, we will create a KB article for this.
    ?
    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
    ?
    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.