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.

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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');

Method 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' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x