Site logo

Archived topic

Hide screen options on custom-post-type

6 replies · Started by Rodrigo on October 24, 2016

Viewing posts 1–7 of 7

Hi Tom,

I have three different post types (post, video, slider) on my WP site with GeneratePress, and I want to hide various screen options for the users.

I already hide the screen options for posts, with the following filter:

add_filter('default_hidden_meta_boxes','hide_meta_box',10,2);
function hide_meta_box($hidden, $screen) {
    //make sure we are dealing with the correct screen
    if ( ('post' == $screen->base) && ('my-custom-post_type' == $screen->id) ){
      //lets hide everything
      $hidden = array('formatdiv','generate_blog_post_class_meta_box','generate_layout_meta_box','generate_footer_widget_meta_box','generate_pagebuilder_meta_box','generate_de_meta_box','trackbacksdiv','postcostum','commentstatusdiv','commentdiv','slugdiv', 'authordiv','mymetabox_revslider_0','sharing_meta','advads-ad-settings');
      $hidden[] ='my_custom_meta_box';//for custom meta box, enter the id used in the add_meta_box() function.
    }
    return $hidden;
  }

But I don't know how to do it with the other post types (video & slider).

Besides, I'm adding the filters to the funcions.php file of the GeneratePress child theme, but I don't know if that's the best way todo it. What would you recommend to do?

Thanks ins advance,

Just came across this so I thought I would share it.

Here's how to remove meta boxes for custom post types:

add_action( 'add_meta_boxes', 'tu_remove_meta_boxes', 999 );
function tu_remove_meta_boxes() {
	// Disable elements
	remove_meta_box('generate_de_meta_box', 'your_post_type', 'side');
	
	// Footer widgets
	remove_meta_box('generate_footer_widget_meta_box', 'your_post_type', 'side');
	
	// Sidebar layout
	remove_meta_box('generate_layout_meta_box', 'your_post_type', 'side');
	
	// Page builder integration
	remove_meta_box('generate_page_builder_meta_box', 'your_post_type', 'side');
	
	// Page header
	remove_meta_box('generate_page_header_meta_box', 'your_post_type', 'normal');
}

This may be elsewhere, but I thought I'd add this for the new Page Header Selector meta box added in GP Premium 1.4:

// Page header select
remove_meta_box('generate_select_page_header_meta_box', 'your_post_type', 'normal');

Thanks!

Thanks!

In GP 2.0, all of the meta boxes are merged into one, so it'll be much easier to hide :)

Thanks. Updating to Resolved.

I was able to update the above code to the following in 2023 and get this to work.

remove_meta_box('generate_layout_options_meta_box', 'your_post_type', 'side');

This archived topic is closed to new replies.