Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active February 13, 2020 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tommcfarlin/07a77449f7c768ecbbf2 to your computer and use it in GitHub Desktop.
Save tommcfarlin/07a77449f7c768ecbbf2 to your computer and use it in GitHub Desktop.
[WordPress] Using the default_hidden_meta_boxes hook to remove meta boxes from the dashboard of a custom post type.
<?php
add_action( 'default_hidden_meta_boxes', 'acme_remove_meta_boxes', 10, 2 );
/**
* Removes the category, author, post excerpt, and slug meta boxes.
*
* @since 1.0.0
*
* @param array $hidden The array of meta boxes that should be hidden for Acme Post Types
* @param object $screen The current screen object that's being displayed on the screen
* @return array $hidden The updated array that removes other meta boxes
*/
function acme_remove_meta_boxes( $hidden, $screen ) {
if ( 'acme_post_type' == $screen->id ) {
$hidden = array(
'acme_post_type_categorydiv',
'authordiv',
'postexcerpt',
'slugdiv'
);
}
return $hidden;
}
@timotheemoulin
Copy link

Thanks for the tip, but I would rather use hidden_meta_boxes filter instead as default_hidden_meta_boxes might not be triggered depending on your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment