I want to remove the url and add a container(div) around the image in the featured image metabox.

Wordpress output

<p class="hide-if-no-js">
    <a title="Set featured image" href="URL" id="set-post-thumbnail" class="thickbox">IMAGE</a>

at default.

I want the output to be

<p class="hide-if-no-js"><div>IMAGE</div></p> 

Can I do this using the admin_post_thumbnail_html hook? How should I do this?

  • This sounds like an XY problem, why would you want to do this? Is it because you don't want users to be able to edit the featured image, only view it? – Tom J Nowell Sep 14 '14 at 19:18

I am not sure why you want to do this, but you can accomplish it with preg_replace().

Try adding this to your theme's functions.php:

add_filter( 'admin_post_thumbnail_html', 'remove_featured_image_link' );
function remove_featured_image_link($content) {

    $content_edit = preg_replace('/<a .*?class="(.*?thickbox.*?)">(.*?)<\/a>/','<div>$2</div>',$content);

    return $content_edit;

| improve this answer | |

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.