最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to move "Collapse Menu" to top of admin bar?

programmeradmin0浏览0评论

As stated in the title, I try to perpetually move the "Collapse Menu" button which is normally the very last entry in the admin sidebar (backend) to the top. I googled but can't find any working solution.

I found that it is printed through wp-admin/menu-header.php. So I thought I could override this file with my child theme. But then, when a theme update changes the menu-header.php file, I would need to realize and reproduce these changes in the child theme as well. Not very practical...

Anybody got an ideas?

As stated in the title, I try to perpetually move the "Collapse Menu" button which is normally the very last entry in the admin sidebar (backend) to the top. I googled but can't find any working solution.

I found that it is printed through wp-admin/menu-header.php. So I thought I could override this file with my child theme. But then, when a theme update changes the menu-header.php file, I would need to realize and reproduce these changes in the child theme as well. Not very practical...

Anybody got an ideas?

Share Improve this question edited Sep 20, 2019 at 14:34 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Sep 18, 2019 at 22:04 McYodaMcYoda 1
Add a comment  | 

1 Answer 1

Reset to default 0

Rule of thumb is do not modify any core WordPress files. Those in the root, wp-includes, wp-admin. You could do this easily with JavaScript:

/**
 * Move the 'Collapse menu' item to the top of the admin menu
 *
 * @return void
 */
function wpse348570_move_collapse_menu() {

    ?>
        <script>
            if( jQuery( '#collapse-menu' ).length ) {
                jQuery( '#collapse-menu' ).prependTo( '#adminmenu' );
            }
        </script>
    <?php

}
add_action( 'admin_footer', 'wpse348570_move_collapse_menu' );

You can add the above as a plugin or place it into the child theme.

发布评论

评论列表(0)

  1. 暂无评论