3

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.

  • 1
    What "collapse menu"? Please, be as detailed as possible when asking Questions... – brasofilo Mar 1 '13 at 9:32
  • Oops sorry, I meant the one that is on the left side of the admin menu in the dashboard. I'd need it for both admin, authors, contributors... Thanks... – user27309 Mar 1 '13 at 9:47
  • Add details to the Question itself, you are free to edit it whenever needed. – brasofilo Mar 1 '13 at 9:53
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');
  • I tried the code by Pontus Abrahamsson and it works like a charm. I've not tried the one by birgire but it appears to work either... Thank you all! – user27309 Mar 1 '13 at 10:02
1

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');
  • 1
    @Pontus has posted similar solution, while I was writing my answer ;-) – birgire Mar 1 '13 at 10:01
1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.