Block Editor: Add different Instruction Text To Featured Image Box based on CPT
-
Hi,
I would like to add instruction text to the Featured Image Box in the block editor, and I could do this with this code below:
function change_post_type_labels() { $post_object = get_post_type_object( 'post' ); 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 );
I want each custom post type featured image box to have different instructions. I am having trouble with the if else statement, and it seems get_post_type() doesn’t work.
This is what I have below and it’s not working:function change_post_type_labels() { if('post' == get_post_type()){ $post = 'post'; $text = 'Set featured image (540px x 350px)'; }elseif( 'news' == get_post_type()){ $post = 'news'; $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 );
What is the issue?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Block Editor: Add different Instruction Text To Featured Image Box based on CPT’ is closed to new replies.