How to Remove Meta Boxes from Specific Pages

Here is a very simple and robust way to remove meta boxes from specific pages. It will remove the specified boxes from any page slugs in the array of slugs.

Code to Remove Meta Boxes from Specific Pages

add_action('do_meta_boxes', function() {
    $post_id = $_GET['post'] ?? ($_POST ?? false);
    global $edit_post_id;

    // just call it once - don't repeat yo'self!
    if ($edit_post_id !== $post_id) {
        global $post;
        $edit_post_id = $post_id;

        // array of pages that will exclude the meta box(es)
        $exclude_on_pages = [
            'home'
        ];

        // remove the meta box(es) from the specific pages
        if (in_array($post->post_name, $exclude_on_pages)) {
            remove_meta_box('postimagediv', 'page', 'side');
        }
    }
});

Conclusion

Plonk this in a plugin or your theme’s codebase and you’re good to go. Or, if you would like to know more about how you can control the meta boxes on your website, check out these posts on how to move meta boxes and how to move the Yoast meta box down, or read the official WP documentation on <a href="https://developer.wordpress.org/reference/functions/do_meta_boxes/" target="_blank" rel="noopener noreferrer">do_meta_boxes()</a> and  remove_meta_boxes() If you have any questions or would like help with WordPress related challenges, call us and we’ll gladly help.