The post_thumbnail_meta_box()
WordPress PHP function displays the post thumbnail meta box in the WordPress admin panel.
Usage
Here’s how to use the post_thumbnail_meta_box()
function. Assume we have a current post object $post
.
post_thumbnail_meta_box($post);
Parameters
$post WP_Post
(required): This is the current post object.
More Information
See WordPress Developer Resources: post_thumbnail_meta_box()
This function is a part of the WordPress core, and there is currently no deprecation date. For further reference, you can view its source code in the wp-admin/includes/post.php
.
Examples
Displaying a Post Thumbnail Meta Box
Let’s say we want to display the post thumbnail meta box in a custom page for a specific post. The post has an ID of 123.
$post = get_post(123); post_thumbnail_meta_box($post);
Display Post Thumbnail Meta Box in a Custom Admin Page
If you’re creating a custom admin page and you want to include the post thumbnail meta box for a post, you can do that as follows.
$post = get_post(123); add_meta_box('postimagediv', __('Post Image'), 'post_thumbnail_meta_box', null, 'side', 'low', array('post' => $post));