I hope you all have seen wordpress admin panel. We have option at the end of menu to collapse or expand the menu.
If you click on collapse the menu gets collapsed and that settings gets saved ( I don’t know where ) but if you login again you will see the same collapsed menu..
Where are they storing that data ???
I want to make admin menu to be shown collapsed by default how do i do that ?
Edit : I think the file wp-admin/js/common.js is responsible for that..
you can view the file here http://phpcrossref.com/xref/wordpress/wp-admin/js/common.js.txt
I think I got the code which is responsible for that, but I am new to js. The code is as follows :
$('#collapse-menu').on('click.collapse-menu', function() {
var body = $( document.body ), respWidth, state;
// reset any compensation for submenus near the bottom of the screen
$('#adminmenu div.wp-submenu').css('margin-top', '');
if ( window.innerWidth ) {
// window.innerWidth is affected by zooming on phones
respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
} else {
// IE < 9 doesn't support @media CSS rules
respWidth = 961;
}
if ( respWidth && respWidth < 960 ) {
if ( body.hasClass('auto-fold') ) {
body.removeClass('auto-fold').removeClass('folded');
setUserSetting('unfold', 1);
setUserSetting('mfold', 'o');
state = 'open';
} else {
body.addClass('auto-fold');
setUserSetting('unfold', 0);
state = 'folded';
}
} else {
if ( body.hasClass('folded') ) {
body.removeClass('folded');
setUserSetting('mfold', 'o');
state = 'open';
} else {
body.addClass('folded');
setUserSetting('mfold', 'f');
state = 'folded';
}
}
$( document ).trigger( 'wp-collapse-menu', { state: state } );
});
Finally I found the answer :
We just need to add class ‘folded’ in body tag to make admin menu folded. I added the class in body tag using JavaScript : document.body.className+=’ folded’;
here is the complete code that I added to the functions.php ( you can add that to your plugin also )
the code :=
and it worked 🙂
The above solution is a good way to do. But in this solution, we could get to see some flashes, where until the page is loaded and script executes if it is painted, then we might be able to see it open.
I came up with this solution via backend after digging into some core files.
What this does is the same thing, it adds class. Just that it does it from the backend instead of the frontend.
You’ll need to find where the template uses the
auto-fold
andfolded
classes, and make sure that the default isfolded
on page load. I can’t say more until you find out where that is done.