Changing menu order of a specific plugin in dashboard

An extension of this question in a way.

My Wordpress dashboard menu looks like below:

Array
(
    [2] = Array
        (
            [0] = Dashboard
            [1] = read
            [2] = index.php
            [3] = 
            [4] = menu-top menu-top-first menu-icon-dashboard
            [5] = menu-dashboard
            [6] = dashicons-dashboard
        )

    [4] = Array
        (
            [0] = 
            [1] = read
            [2] = separator1
            [3] = 
            [4] = wp-menu-separator
        )

    [10] = Array
        (
            [0] = Media
            [1] = upload_files
            [2] = upload.php
            [3] = 
            [4] = menu-top menu-icon-media
            [5] = menu-media
            [6] = dashicons-admin-media
        )

    [15] = Array
        (
            [0] = Links
            [1] = manage_links
            [2] = edit-tags.php?taxonomy=link_category
            [3] = 
            [4] = menu-top menu-icon-links
            [5] = menu-links
            [6] = dashicons-admin-links
        )

    [25] = Array
        (
            [0] = Comments span class=awaiting-mod count-0span class=pending-count aria-hidden=true0/spanspan class=comments-in-moderation-text screen-reader-text0 Comments in moderation/span/span
            [1] = edit_posts
            [2] = edit-comments.php
            [3] = 
            [4] = menu-top menu-icon-comments
            [5] = menu-comments
            [6] = dashicons-admin-comments
        )

    [5] = Array
        (
            [0] = Posts
            [1] = edit_posts
            [2] = edit.php
            [3] = 
            [4] = menu-top menu-icon-post open-if-no-js
            [5] = menu-posts
            [6] = dashicons-admin-post
        )

    [20] = Array
        (
            [0] = Pages
            [1] = edit_pages
            [2] = edit.php?post_type=page
            [3] = 
            [4] = menu-top menu-icon-page
            [5] = menu-pages
            [6] = dashicons-admin-page
        )

    [26] = Array
        (
            [0] = Templates
            [1] = edit_posts
            [2] = edit.php?post_type=elementor_library
            [3] = 
            [4] = menu-top menu-icon-elementor_library
            [5] = menu-posts-elementor_library
            [6] = dashicons-admin-page
        )

    [27] = Array
        (
            [0] = Donations
            [1] = edit_give_forms
            [2] = edit.php?post_type=give_forms
            [3] = 
            [4] = menu-top menu-icon-give_forms
            [5] = menu-posts-give_forms
            [6] = dashicons-give
        )

    [6] = Array
        (
            [0] = WP Links Page
            [1] = manage_options
            [2] = edit.php?post_type=wplp_link
            [3] = 
            [4] = menu-top menu-icon-wplp_link
            [5] = menu-posts-wplp_link
            [6] = dashicons-admin-links
        )

    [59] = Array
        (
            [0] = 
            [1] = read
            [2] = separator2
            [3] = 
            [4] = wp-menu-separator
        )

    [60] = Array
        (
            [0] = Appearance
            [1] = switch_themes
            [2] = themes.php
            [3] = 
            [4] = menu-top menu-icon-appearance
            [5] = menu-appearance
            [6] = dashicons-admin-appearance
        )

    [65] = Array
        (
            [0] = Plugins span class=update-plugins count-4span class=plugin-count4/span/span
            [1] = activate_plugins
            [2] = plugins.php
            [3] = 
            [4] = menu-top menu-icon-plugins
            [5] = menu-plugins
            [6] = dashicons-admin-plugins
        )

    [70] = Array
        (
            [0] = Users
            [1] = list_users
            [2] = users.php
            [3] = 
            [4] = menu-top menu-icon-users
            [5] = menu-users
            [6] = dashicons-admin-users
        )

    [75] = Array
        (
            [0] = Tools
            [1] = edit_posts
            [2] = tools.php
            [3] = 
            [4] = menu-top menu-icon-tools
            [5] = menu-tools
            [6] = dashicons-admin-tools
        )

    [80] = Array
        (
            [0] = Settings
            [1] = manage_options
            [2] = options-general.php
            [3] = 
            [4] = menu-top menu-icon-settings
            [5] = menu-settings
            [6] = dashicons-admin-settings
        )

    [99] = Array
        (
            [0] = 
            [1] = read
            [2] = separator-last
            [3] = 
            [4] = wp-menu-separator
        )

    [30] = Array
        (
            [0] = Contact
            [1] = wpcf7_read_contact_forms
            [2] = wpcf7
            [3] = Contact Form 7
            [4] = menu-top toplevel_page_wpcf7
            [5] = toplevel_page_wpcf7
            [6] = dashicons-email
        )

    [100] = Array
        (
            [0] = Slider Revolution
            [1] = manage_options
            [2] = revslider
            [3] = Slider Revolution
            [4] = menu-top toplevel_page_revslider
            [5] = toplevel_page_revslider
            [6] = dashicons-update
        )

What code can I put in theme's functions.php to change entry #6 WP Links Page to always be below Pages (i.e. in the 20s range, according to this advice)?

Actual

Desired

Topic menu-order dashboard plugins Wordpress

Category Web


I could see "WP Links Page" is a custom post type, so if it's not registered by your own code, e.g. it's registered by a plugin (using register_post_type()), then you can use the register_post_type_args filter to change the menu_position argument like so:

add_filter( 'register_post_type_args', 'my_override_register_post_type_args', 10, 2 );
function my_override_register_post_type_args( $args, $post_type ) {
    // Move "WP Links Page" to below the "Pages". You could also try using 21 instead.
    if ( 'wplp_link' === $post_type ) {
        $args['menu_position'] = 20;
    }

    return $args;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.