How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button

I have a custom post type (called contacts).
Since this post type is not working like a post, I don’t want to show SAVE DRAFT, PREVIEW, Status, Visibility or Publish Date.

The only options I want to show are PUBLISH & Move to Trash buttons.

Read More

Is there a way to hide these other options? If not, how do I create a new PUBLISH & Move to Trash that I can add to a new metabox?

Related posts

Leave a Reply

2 comments

  1. You can simply hide the options using CSS. This will add a display:none style to the misc and minor publishing actions on the post.php and post-new.php pages. It checks for a specific post type as well since all post types use these two files.

    function hide_publishing_actions(){
            $my_post_type = 'POST_TYPE';
            global $post;
            if($post->post_type == $my_post_type){
                echo '
                    <style type="text/css">
                        #misc-publishing-actions,
                        #minor-publishing-actions{
                            display:none;
                        }
                    </style>
                ';
            }
    }
    add_action('admin_head-post.php', 'hide_publishing_actions');
    add_action('admin_head-post-new.php', 'hide_publishing_actions');
    
  2. In this example you can easily set on which post types you want to hide the publishing options, the example hides them for the build-in pots type type page and the custom post type cpt_portfolio.

    /**
     * Hides with CSS the publishing options for the types page and cpt_portfolio
     */
    function wpse_36118_hide_minor_publishing() {
        $screen = get_current_screen();
        if( in_array( $screen->id, array( 'page', 'cpt_portfolio' ) ) ) {
            echo '<style>#minor-publishing { display: none; }</style>';
        }
    }
    
    // Hook to admin_head for the CSS to be applied earlier
    add_action( 'admin_head', 'wpse_36118_hide_minor_publishing' );
    

    Important update

    I would also suggest you force a post status of “Published” to avoid saving posts as drafts:

    /**
     * Sets the post status to published
     */
    function wpse_36118_force_published( $post ) {
        if( 'trash' !== $post[ 'post_status' ] ) { /* We still want to use the trash */
            if( in_array( $post[ 'post_type' ], array( 'page', 'cpt_portfolio' ) ) ) {
                $post['post_status'] = 'publish';
            }
            return $post;
        }
    }
    
    // Hook to wp_insert_post_data
    add_filter( 'wp_insert_post_data', 'wpse_36118_force_published' );