How to disable or hide “collapse menu”

Is there a code in functions.php that I can add to disable or hide “collapse menu” button?

The one that is on the left side of the admin menu in the dashboard. I’d need it for both admin, authors, contributors.

Related posts

Leave a Reply

3 comments

  1. Here is a simple css display: none function, it just adds some css in the html, if there are more stuff that you want to hide i recommend you to add a new css-file with the function admin_enqueue_scripts

    function wpse_remove_collapse() {
       echo '<style type="text/css">#collapse-menu { display: none; visibility: hidden; }</style>';
    }
    add_action('admin_head', 'wpse_remove_collapse');
    
  2. You can’t use remove_menu() for this one, since it is added like this in the admin menu

        echo '<li id="collapse-menu" class="hide-if-no-js"><div id="collapse-button"><div></div></div>';
        echo '<span>' . esc_html__( 'Collapse menu' ) . '</span>';
        echo '</li>';
    

    in the _wp_menu_output() function in /wp-admin/menu-header.php.

    So you could try instead:

    function wpse88939_hide_collapse_button_menu() {
            echo "<style>#collapse-menu{display:none !important;} </style>";
    }
    add_action('admin_head','wpse88939_hide_collapse_button_menu');
    
  3. Making the text something different might also be handy:

    add_filter ( 'gettext', 'wsfilter_collapseMenu', 10, 3 );
    
    function wsfilter_collapseMenu($translated, $original, $domain) {
      if ($original == 'Collapse menu')
        return 'Hide navigation'; 
      else
        return $translated;
    }
    

    Or making the text completely blank but keeping the little arrow with hide/show functionality:

    add_filter ( 'gettext', 'wsfilter_collapseMenu', 10, 3 );
    
    function wsfilter_collapseMenu($translated, $original, $domain) {
      if ($original == 'Collapse menu')
        return ''; 
      else
        return $translated;
    }