Last active
June 6, 2019 05:42
-
-
Save mohsinworld/6d3d93f1d3289325d36c2f495bc6d7ae to your computer and use it in GitHub Desktop.
This code need to use in functions.php file (themes files)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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