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?

1 Answer
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().

Leave a Reply

Your email address will not be published. Required fields are marked *