Skip to content

Instantly share code, notes, and snippets.

@DevinWalker
Created May 14, 2014 20:32
Show Gist options
  • Select an option

  • Save DevinWalker/ee9d4e53883460c6bbb8 to your computer and use it in GitHub Desktop.

Select an option

Save DevinWalker/ee9d4e53883460c6bbb8 to your computer and use it in GitHub Desktop.
This code removed the Revolution Slider metabox on pages, posts and CTPs
/**
* Remove Rev Slider Metabox
*/
if ( is_admin() ) {
function remove_revolution_slider_meta_boxes() {
remove_meta_box( 'mymetabox_revslider_0', 'page', 'normal' );
remove_meta_box( 'mymetabox_revslider_0', 'post', 'normal' );
remove_meta_box( 'mymetabox_revslider_0', 'YOUR_CUSTOM_POST_TYPE', 'normal' );
}
add_action( 'do_meta_boxes', 'remove_revolution_slider_meta_boxes' );
}
@MarliBells
Copy link
Copy Markdown

Very helpful, thanks!

@JoshMountain
Copy link
Copy Markdown

Thanks Devin, exactly what I was looking to do.

@jotapepinheiro
Copy link
Copy Markdown

lol

@fabianmarz
Copy link
Copy Markdown

Thanks!

@pixelkicks
Copy link
Copy Markdown

Perfect, much tidier without the metabox appearing everywhere.

@sixtyseven-multimedia
Copy link
Copy Markdown

Exactly what I was looking for. There should be a plugin setting for this, though ...

Any idea how to get the same result for the Post Property metabox from te same plugin?

Greetings from germany!

@adrianf
Copy link
Copy Markdown

adrianf commented Jun 4, 2015

Thanks! Where is the best place to put this code?

@jstensved
Copy link
Copy Markdown

@adrianf functions.php

@aaemnnosttv
Copy link
Copy Markdown

Ugh, this has been bugging me forever. Nice to see I'm not the only one 👍

I've improved on this a bit so we can remove it on all custom post type edit screens.

Load this somewhere before init:

/**
 * Helper for removing the Revslider Metabox from being on every CPT edit screen
 *
 * @param $post_type
 */
function remove_revslider_metabox($post_type)
{
    add_action('do_meta_boxes', function () use ($post_type) {
        remove_meta_box('mymetabox_revslider_0', $post_type, 'normal');
    });
}
add_action('registered_post_type', 'remove_revslider_metabox');

Alternatively skip the add_action on registered_post_type and selectively choose which to exclude and call remove_revslider_metabox for each one. No reason to wrap with is_admin(), as that action won't be triggered on the front end and there's no overhead to just adding a callback.

@ajithrn
Copy link
Copy Markdown

ajithrn commented Aug 27, 2016

very helpful, thanks 👍

@nguyentrangdong
Copy link
Copy Markdown

many thanks

@stieranka
Copy link
Copy Markdown

thanks!

@acewebsa
Copy link
Copy Markdown

acewebsa commented Aug 7, 2017

Brilliant. This was exactly what I was after. I was getting annoyed at it being on every custom post type. Thank you!

@Luc45
Copy link
Copy Markdown

Luc45 commented Aug 28, 2017

Thanks! These guys are fucking dickheads for putting that on every post type!!!

@aronmoshe-m
Copy link
Copy Markdown

Super helpful and just what I needed. Thank you!

@k4mrul
Copy link
Copy Markdown

k4mrul commented Sep 22, 2017

Thanks mate

@mattjdever
Copy link
Copy Markdown

Thank you so much. I was getting frustrated seeing this everywhere and various similar attempts of mine were just not working.

@mattjdever
Copy link
Copy Markdown

Also, if anyone is using this for removing other annoying metaboxes put by plugin creators that assume you want thier metaboxes in all of your CPT edit pages, check if the metabox is in the normal-sortables div, or the advanced-sortables div. If it is in advanced-sortables, just change the last parameter to 'advanced'

example:
remove_meta_box('page-links-to', $post_type, 'advanced');

Note to plugin developers: Please consider the effect of your cool ideas on other plugins that may be using Custom Post Types. Either limit the effect of your metaboxes by explicitly attaching them to the post type, or allow the toggling of them in other CPTs.

Thanks again!

@jcorreia
Copy link
Copy Markdown

complemented to woocomerce products, categories, etc with post types in this page https://docs.woocommerce.com/document/installed-taxonomies-post-types/


function remove_revolution_slider_meta_boxes() {
	remove_meta_box( 'mymetabox_revslider_0', 'page', 'normal' );
	remove_meta_box( 'mymetabox_revslider_0', 'post', 'normal' );
	remove_meta_box( 'mymetabox_revslider_0', 'product', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'product_cat', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'product_tag', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'product_variation', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'product_visibility', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'shop_order', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'shop_order_status', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'shop_order_refund', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'shop_coupon', 'normal' );
        remove_meta_box( 'mymetabox_revslider_0', 'shop_webhook', 'normal' );

}

add_action( 'do_meta_boxes', 'remove_revolution_slider_meta_boxes' );

Thanks !

@brianlayman
Copy link
Copy Markdown

brianlayman commented Aug 21, 2019

The do_meta_boxes filter is run 3 times for every editor page load. Once for each context.

So using jcorreia's example from the woocommerce docs, it will call remove_meta_box 36 times (3 * 12) and most of those calls are unneeded. All 36 of them are unneeded if you aren't even on one of those post types. You only need to remove the metabox when you are opening one of the editors for those particular post types.

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
		}
	}
}

@Mark-Creeten
Copy link
Copy Markdown

Mark-Creeten commented Sep 19, 2019

@brianlayman, did you forgot to set the $postType?

like:

 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.
	// Remove this line and it will check all contexts in case the box has been moved by user
	if ( 'normal' !== $context ) return; 

	// 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' ) ) {
		//get the current post type to use in the in_array()
		$postType = get_post_type();
		// PostTypes hiding this metabox. This could be an object var from $this
		$postTypes = array( 'posttype1', 'posttype2', 'page' ); 
		if ( in_array ( $postType, $postTypes ) ) {
			remove_meta_box( 'wpseo_meta', $postType, $context);
			remove_meta_box( 'postcustom', $postType, $context );
			remove_meta_box( 'rs-addon-typewriter-meta', $postType, $context );
			remove_meta_box( 'mymetabox_revslider_0', $postType, $context ); // Could add _1 _2 etc in case of multiple sliders per page
		}
	}
}

in addition to the solution from @brianlayman, if you have Revolution slider version 6, the metabox ID == 'eg-meta-box'

@brianlayman
Copy link
Copy Markdown

brianlayman commented Sep 19, 2019

@Mark-Creeten
Ah, yes, my original code had a different condition. So I edited that sample in the gist text editor and didn't test the edit on a site. Thanks for catching that.

@ethanclevenger91
Copy link
Copy Markdown

Slider Revolution version 6.5.19, the meta box slug is slider_revolution_metabox and its context is side. So wherever you put it, the call needs to be:

remove_meta_box('slider_revolution_metabox', $post_type, 'side');

@brianlayman
Copy link
Copy Markdown

Slider Revolution version 6.5.19, the meta box slug is slider_revolution_metabox and its context is side.

In my example then, the context check could handled as a switch clause to have the remove_meta_box calls still only execute once for each appropriate context.

@suhakaralar
Copy link
Copy Markdown

function remove_revolution_slider_meta_box() {
$contexts = array( 'normal', 'advanced', 'side' );
foreach ( $contexts as $context ) {
$result = remove_meta_box( 'slider_revolution_metabox', null, $context );
error_log( 'Removing metabox from context: ' . $context . ' Result: ' . ( $result ? 'Success' : 'Failed' ) );
}
}

add_action( 'add_meta_boxes', 'remove_revolution_slider_meta_box', 99 );

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