Skip to content

Instantly share code, notes, and snippets.

@melvinstanly
Created July 29, 2021 08:36
Show Gist options
  • Save melvinstanly/8b61124563cc2de27fef365beb85457d to your computer and use it in GitHub Desktop.
Save melvinstanly/8b61124563cc2de27fef365beb85457d to your computer and use it in GitHub Desktop.
Hide WordPress admin sidebar in wordpress pages
<?php
// Fold / unfold the WordPress admin sidebar in certain pages. Set `mfold` to `f`(fold) to close it and `o`(open) to open the sidebar.
add_action('admin_init', 'collapse_admin_sidebar');
function collapse_admin_sidebar(){
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : false;
if( $page === "required_page_slug" ){
if( get_user_setting('mfold') != 'f' ){
set_user_setting('mfold', 'f');
}
}else{
set_user_setting('mfold', 'o');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment