0

I have installed Jetpack and now my custom post types feature a meta-box that says "Sharing: Show sharing buttons" with a checkbox. This is unnecessary for this custom post type and I would like to remove it altogether (not just hide it via screen options).

I tried adding

add_action( 'init', array( $this, 'my_remove_filters_func' ) );

function my_remove_filters_func() {
    remove_all_filters( 'the_content', 'sharing_display',19 );
    remove_all_filters( 'the_excerpt', 'sharing_display',19 );
}

however it doesn't seem to be working

1

you can try this

if (is_admin()){
  function my_remove_meta_boxes() {
    global $typenow;
    if( 'YOUR_CUSTOM_POST_TYPE' == $typenow ) {
      remove_meta_box('sharing_meta', 'YOUR_CUSTOM_POST_TYPE', 'high');
    }
  }
  add_action( 'admin_menu', 'my_remove_meta_boxes' );
}

Which removes the metabox registered by the jetpack plugin. Just make sure to change YOUR_CUSTOM_POST_TYPE with the actual name of your custom post type.

2

As of Jetpack 3.8.0, the metaboxes can be remove using a filter:

add_filter( 'sharing_meta_box_show', '__return_false' );

So, on a custom post type page, you can use this method:

add_action( 'current_screen', function() {
    $screen = get_current_screen();

    if ( ! empty( $screen->post_type ) && '%POST_TYPE%' === $screen->post_type ) {
        add_filter( 'sharing_meta_box_show', '__return_false' );
    }
});

Just replace %POST_TYPE% with your custom post type.

  • This gets it right. No fiddling necessary. – Kaji Nov 16 '17 at 0:46
1

The code in the accepted solution didn't work for me because admin_menu was firing too early. Also, high is not a valid argument for remove_meta_box, so I used advanced instead.

Here's the updated code:

if ( is_admin() ){
    function my_remove_meta_boxes() {
        global $typenow;
        if( 'YOUR_CUSTOM_POST_TYPE' == $typenow ) {
            remove_meta_box( 'sharing_meta', 'YOUR_CUSTOM_POST_TYPE', 'advanced' );
        }
    }
    add_action( 'do_meta_boxes', 'my_remove_meta_boxes' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.