1

I'd like to be able to edit the description/help text that appears beneath the field in the CMS page editor for a custom post type.

I know I can change the name and button/link text by passing items into the labels array in register post type.

'featured_image' => __('Foo'),
'set_featured_image' => __('Set Foo'),
'remove_featured_image' => __('Remove Foo'),
'use_featured_image' => __('Use as Foo')

But is there a way to add to edit the help text that displays beneath the field? It says "Click the image to edit or update" if an image is selected. I'd like to add further instructions as to precisely what kind of image to use.

Ideally this text should appear before an image is selected as well as after. But I'd settle for being able to edit the text that shows after.

  • wouldn't you want to change the text BEFORE you upload an image that says "et featured image" – RiddleMeThis Dec 6 '18 at 18:17
  • Yes. By default there's no help text until after an image has been selected. It'd be great to have it display all the time if possible. I'll settle for changing the text that shows after, as in this case the field will be initially populated with a correct image, but I need to add a warning not to mess with it unless you know what you're doing. – dave Dec 6 '18 at 18:20
  • OK, I've added both sections to the answer – RiddleMeThis Dec 6 '18 at 18:33
1

The following will add help text to the initial "Set featured image" text.

Add the following to your theme's functions.php. Replace "Your custom text goes here" with your help text.

Tested and works.

function custom_featured_image_text( $content ) {
    return '<p>' . __('Your custom text goes here') . '</p>' . $content;
}
add_filter( 'admin_post_thumbnail_html', 'custom_featured_image_text' );

The following will add help text to the "Click the image to edit or update" text after you upload an image.

function custom_featured_image_text_2( $content ) {
    return str_replace(__('Click the image to edit or update'), __('Your custom text goes here'), $content);
}
add_filter( 'admin_post_thumbnail_html', 'custom_featured_image_text_2' );
0

@RiddleMeThis got me pointed in the right direction, but I needed it to only apply to a single post type so this is my solution:

add_filter('admin_post_thumbnail_html', function ($content) {
    global $pagenow;

    $isNewFoo = 'post-new.php' === $pagenow && isset($_GET['post_type']) && $_GET['post_type'] === 'foo';
    $isEditFoo = 'post.php' === $pagenow && isset($_GET['post']) && get_post_type($_GET['post']) === 'foo';

    if ($isNewFoo || $isEditFoo) {get_post_type($_GET['post']) === 'foo') {
        return '<p>' . __('Your custom text goes here') . '</p>' . $content;
    }

    return $content;
});
  • You should accept one of these answers since you have it figured out. – RiddleMeThis Dec 10 '18 at 16:30
  • Thanks for the reminder. SO wouldn't let me accept my own answer on the same day. – dave Dec 10 '18 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.