Delete all thumbnails for a post

I have a function that sideloads a YouTube thumbnail onto a page… but I want to remove the featured thumb on the page first (and remove all the various auto-generated sizes, too).

I’m assuming I want to use delete_post_thumbnail() followed by wp_delete_attachment() to un-associated the thumb from the post, and then kill the thumb file. Is that correct? And Will that also delete all the various thumb media files (the extra auto-generated sizes) from the disk?

Related posts

1 comment

  1. Using wp_delete_attachment( $attachmentid, true ) is only thing you need.

    Passing true as second argument, ($force_delete see codex ) it:

    • remove the thumbnail association with any post
    • delete any taxonomy associated to attachment
    • and of course remove all the files, also the autogenerated ones

    So you do not need to also use delete_post_thumbnail().

Comments are closed.