Created
March 22, 2013 03:35
-
-
Save spencejs/5218759 to your computer and use it in GitHub Desktop.
Add Instruction Text To Featured Image Box In Wordpress Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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>'; | |
} |
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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can try this way, It's working for me.