Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohsinworld/6d3d93f1d3289325d36c2f495bc6d7ae to your computer and use it in GitHub Desktop.
Save mohsinworld/6d3d93f1d3289325d36c2f495bc6d7ae to your computer and use it in GitHub Desktop.
This code need to use in functions.php file (themes files)
add_action( 'before_delete_post', 'wps_remove_attachment_with_post', 10 );
function wps_remove_attachment_with_post($post_id)
{
if(has_post_thumbnail( $post_id ))
{
$attachment_id = get_post_thumbnail_id( $post_id );
wp_delete_attachment($attachment_id, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment