admin_post_thumbnail_html

Home » Hooks » admin_post_thumbnail_html

The admin_post_thumbnail_html hook is a WordPress filter that allows developers to modify the HTML output of the featured image meta box in the WordPress admin panel. This hook is particularly useful for theming purposes, as it enables developers to customize the appearance of the meta box to fit the specific needs of their website or project.

When called, the admin_post_thumbnail_html hook passes two arguments: the current HTML output of the featured image meta box, and the post ID of the current post being edited. Developers can then modify the HTML output as needed, either by adding or removing elements, changing the style or structure of the HTML, or otherwise manipulating the output.

Here is an example of how to use the admin_post_thumbnail_html hook to modify the featured image meta box:

function custom_featured_image_meta_box($content, $post_id) {
  // Modify the HTML output of the featured image meta box here
  $new_content = '<div class="custom-featured-image">' . $content . '</div>';

  // Return the modified HTML output
  return $new_content;
}
add_filter('admin_post_thumbnail_html', 'custom_featured_image_meta_box', 10, 2);

In this example, we’ve created a custom function called custom_featured_image_meta_box that accepts the current HTML output and post ID as arguments. We then modify the HTML output by wrapping it in a new <div> element with a custom class name. Finally, we return the modified HTML output using the return statement and pass our function to the add_filter function, along with the admin_post_thumbnail_html hook name and a priority of 10. This will apply our custom function to the featured image meta box and modify its HTML output accordingly.

Learn More on WordPress.org

WordPress snippets using the admin_post_thumbnail_html hook

Register an account to save your snippets or go Pro to get more features.