Skip to content

Instantly share code, notes, and snippets.

@spencejs
Created March 22, 2013 03:35
Show Gist options
  • Save spencejs/5218759 to your computer and use it in GitHub Desktop.
Save spencejs/5218759 to your computer and use it in GitHub Desktop.
Add Instruction Text To Featured Image Box In Wordpress Admin
@ivcreative
Copy link

This works fine but not on the Gutenberg pages, will be back if I ever find a solution for it

@jezremy
Copy link

jezremy commented Jul 21, 2020

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 );

@r-interactive
Copy link

jezremy

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