How to change featured image metabox title, position and content in WordPress » WPTechie

The featured image feature was introduced back in version 2.9. It can be used to represent specific post’s image.

We create custom WordPress websites and plugins for our customers. While creating sites I noticed most of developers use featured image option but they don’t change the title of featured image box.

change featured image metabox title, position and content

It’s not necessary to change the title but its good practice if you change the title of featured image metabox because customers are end users and they don’t know how and why you used featured image.

For example, we are creating an event site having event’s image feature. If we don’t change featured image metabox title, customer won’t get idea for the first time but if we change the featured image box title to something like “event image” then customer will get idea easily.

Let’s see how we can change the title of featured image metabox.

How to change featured image metabox title

There is a small snippet to change the title of the featured image box.

function wpt_event_image_box() {
     remove_meta_box('postimagediv', 'event', 'side');	// Remove the default metabox
     // Add it with another title especially for event post type
     add_meta_box('postimagediv', __(' Event\'s Image '), 'post_thumbnail_meta_box', 'event', 'side', 'low');
}
add_action('do_meta_boxes', 'wpt_event_image_box');
change featured image metabox title, position and content
Before adding our code
change featured image metabox title, position and content
After adding our code

As you can see in the above images, the Event’s Image title makes more sense than Featured Image.

Change the featured image metabox position

The above code simply changes the title of the featured Image box, but we can also change the position by just changing the fifth and sixth parameter.

add_meta_box('postimagediv', __('Event\’s Image'), 'post_thumbnail_meta_box', 'event', 'side', 'low');

In the above code, we used side, and low as a value of the fifth and sixth parameter. It means the featured image box should display on the right side with the lowest priority. We can change “side” to either “normal” or “advanced”. The default is “advanced”.

If you want to change the priority of the featured image box, you can simply change the last parameter from “low” to “high”.

Changing the featured image box content and link title

We changed the title of the featured image box but the link to add image still has “featured” text and it’s better to rename it to “Add event image” and “Remove event image”.

change featured image metabox title, position and content
Before adding image
change featured image metabox title, position and content
After adding image

We can achieve this with following code snippet:


function wpt_featured_box_htm( $content ) {
     if ( 'events' === get_post_type() ){	//check if it's our custom post type
        $content = 'Add event image here'.$content;	//add some description to featured image box
	$content = str_replace(__('Set featured image'), __('Add event image'),$content);	//rename the add image link title
	$content = str_replace(__('Remove featured image'), __('Remove event image'),$content);	//rename remove image link title
     }
     return $content;	//return our modified content for featured image box
}
add_filter( 'admin_post_thumbnail_html', 'wpt_featured_box_htm' );

That’s it. We are done 🙂

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...


Love this post? Sign Up below to get more tutorials and tips like this in your Inbox