-
-
Save spencejs/5218759 to your computer and use it in GitHub Desktop.
//Add Instructions to Featured Image Box | |
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_html'); | |
function add_featured_image_html( $html ) { | |
return $html .= '<p>This is some sample text that can be displayed within the feature image box.</p>'; | |
} |
How to show this only for specific post type? I tried this:
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_html');
function add_featured_image_html( $html ) {
$pt = get_current_screen()->post_type;
if ( $pt != 'post') return;
return $html .= "This is some sample text that can be displayed within the feature image box.";
}but it hides the "Set featured image" link from the other post types.
You can try this way, It's working for me.
//Add Instructions to Featured Image Box
function ration_add_featured_image_html( $html ) {
if(get_post_type() === 'our-experts') {
$html .= '<p>Recommended dimension, 540x350.</p>';
}
return $html;
}
add_filter( 'admin_post_thumbnail_html', 'ration_add_featured_image_html');
This works fine but not on the Gutenberg pages, will be back if I ever find a solution for it
You can do this in Gutenberg and the Classic Editor by amending the labels for the post type = post (or a custom post type):
//Add Instructions to Featured Image Box function change_post_type_labels() { $post_object = get_post_type_object( 'our-experts' ); if ( ! $post_object ) { return false; } $post_object->labels->set_featured_image = 'Set featured image (540px x 350px)'; return true; } add_action( 'wp_loaded', 'change_post_type_labels', 20 );
Hi jezremy ,
the code works, but how can I do this for multiple Custom post types. I want each custom post type featured image box to have different instructions. I am having trouble coding the if else statement, seems that get_post_type() doesn't work.
This is what I have:
`function change_post_type_labels() {
if('news' == get_post_type()){
$post = 'news';
$text = 'Set featured image (540px x 350px)';
}elseif( 'page' == get_post_type()){
$post = 'page';
$text = 'Set featured image (600px x 300px)';
}
$post_object = get_post_type_object( $post);
if ( ! $post_object ) {
return false;
}
$post_object->labels->set_featured_image = $text;
return true;
}
add_action( 'wp_loaded', 'change_post_type_labels', 20 );`
Would you know what the issue is?
Thanks!
How to show this only for specific post type? I tried this:
but it hides the "Set featured image" link from the other post types.