Last active
October 15, 2022 05:05
-
-
Save brianlayman/e615fcf8449c819d931b2eda82f78b91 to your computer and use it in GitHub Desktop.
How to force hide metaboxes on specific post type editor pages: RevSlider WPSEO by Yoast, whatever.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The do_meta_boxes filter is run 3 times for every editor page load. Once for each context. | |
So you only need to remove the metabox if you are in an editor you care about. | |
There are 3 parameters sent in the do_meta_boxes filter. So add the action this way: | |
`add_action( 'do_meta_boxes', 'remove_unwanted_metaboxes', 10, 3 );` | |
And then do something like this: | |
``` | |
function remove_unwanted_metaboxes( $type, $context, $post ) { | |
// This action will be executed for all context: normal, advanced and side | |
// If you want to run it only for the normal context, you can. | |
if ( 'normal' !== $context ) return; // Remove this line and it will check all contexts in case the box has been moved by user | |
// get_current_screen() is defined on most admin pages, but not all. | |
// The ones that don't have it won't have metaboxes we care about. | |
if ( function_exists( 'get_current_screen' ) ) { | |
$curPostType = get_post_type(); // Get the current posttype | |
$postTypesToCheck = array( 'posttype1', 'posttype2', 'page' ); // PostTypes hiding this metabox. This could be an object var from $this | |
if ( in_array ( $curPostType, $postTypesToCheck ) ) { | |
remove_meta_box( 'wpseo_meta', $curPostType, $context ); | |
remove_meta_box( 'postcustom', $curPostType, $context ); | |
remove_meta_box( 'rs-addon-typewriter-meta', $curPostType, $context ); | |
remove_meta_box( 'mymetabox_revslider_0', $curPostType, $context ); // Could add _1 _2 etc in case of multiple sliders per page | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment