Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function auto_delete_images_on_post_delete( $post_id ) {
- // Get the post object
- $post = get_post( $post_id );
- // Get any attached images
- $images = get_attached_media( 'image', $post_id );
- // Loop through the images and delete them
- foreach ( $images as $image ) {
- wp_delete_attachment( $image->ID, true );
- }
- }
- // Hook the function to the 'before_delete_post' action
- add_action( 'before_delete_post', 'auto_delete_images_on_post_delete' );
Advertisement
Add Comment
Please, Sign In to add comment