BBQ WP Plugin Pro-By Media Ads Labs 2

BBQ WP Plugin Pro-By Media Ads Labs

BBQ WP Plugin Pro-By Media Ads Labs Block Bad Query's WP Plugin Pro No settings need install , activate and that's it You are Done. This Plugin Will Block The More Common Bad Query's. You Can Download I...
0.0Add Your Rating

WP Media List Pro-By Media Ads Labs

WP Media List Pro-By Media Ads Labs Todos Os Usuarios Que Comentão No Seu Blog Serão Adicionados Automaticamente a Sua List, Compativel Com Aweber, GetResponse, Mailchimp, icontact, imnica. Completamente ...
Ascii art work By Media Ads labs 2

Ascii art work By Media Ads labs

Ascii art work By Media Ads labs Animated Ascii art work Reading Source From Wikipedia - ASCII art is a graphic design technique that uses computers for presentation and consists of pictures pieced to...
How to Remove featured image when deleting post with wp_delete_attachment
0.0Give Your Review To This Article

How to Remove featured image when deleting post with wp_delete_attachment

In a recent project I needed to create posts and upload images from the front end as featured image. So as a result I also needed to remove these attachments when people deleted the posts. Otherwise we would have a lot of orphan images using up lots of precious space in our WordPress Media Library. Adding this snippet to the functions.php of your WordPress theme will remove featured images when you delete a post using before_delete_post hook. You will want to be careful with this snippet if you attach the same image to multiple posts as the featured image so keep that in mind. One other thing to remember is that media library items are deleted when the post is deleted not put into trash so you will need to fully delete the post to see the image removed. ( CLICK CODE TO COPY ) WORDPRESS SNIPPET : PHP <> 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); } } ( WordPress codex functions, hooks, in this snippet. ) delete_post, get_post, has_post_thumbnail, wp_delete_attachment, add_action, wp,