1

When I am creating/editing a post and set the featured image, I’d like to display a message to the screen if the file dimensions or size are below a certain threshold. But I want the featured image to still be set.

The message is simply a reminder to myself if I have set a featured image that doesn’t meet certain criteria. I need to do this BEFORE saving the post, ideally right after I set the featured image.

I couldn’t determine which add_filter I would use in my child functions.php to display a message at this point.

I found this example ( https://developer.wordpress.org/reference/hooks/admin_post_thumbnail_html/#user-contributed-notes ) but couldn't get it to work.

Do you have a recommendation?

UPDATE: It turns out that admin_post_thumbnail_html filter no longer works in WordPress > 5.0 : https://core.trac.wordpress.org/ticket/45688 And doing something comparable since 5.0 seems convoluted/requires javascript: https://github.com/danielbachhuber/gutenberg-migration-guide/blob/master/filter-admin-post-thumbnail-html.md

1 Answer 1

0

A nearly identical use case for your question is found in the WordPress documentation for the filter admin_post_thumbnail_html.

A filter hooked to this will receive the HTML for the admin screen as $content. Modify and return this markup as you wish.

function filter_featured_image_admin_text( $content, $post_id, $thumbnail_id ){
    $help_text = '<p>' . __( 'Please use an image that is 1170 pixels wide x 658 pixels tall.', 'my_domain' ) . '</p>';
return $help_text . $content;
}

add_filter( 'admin_post_thumbnail_html', 'filter_featured_image_admin_text', 10, 3 );

Full details here: https://developer.wordpress.org/reference/hooks/admin_post_thumbnail_html/

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.