Is there a way to delete images from WordPress media library programmatically?

This can be achieved with wp_delete_attachment( $attachment->ID ); Here’s an example to delete all attachments related to a post: // Delete Attachments from Post ID 25 $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => 25, ) ); foreach ( $attachments as $attachment ) { wp_delete_attachment( $attachment->ID ); }

Remove image classes from post thumbnail output

You might try something like this in your functions.php: //remove class from the_post_thumbnail function the_post_thumbnail_remove_class($output) { $output = preg_replace(‘/class=”.*?”https://wordpress.stackexchange.com/”, ”, $output); return $output; } add_filter(‘post_thumbnail_html’, ‘the_post_thumbnail_remove_class’);

add_image_size() to crop images into squares?

If you pass true for the last $crop argument then so called “hard” crop mode is used. This will make WP produce results at exact size specified, except few edge cases (if image uploaded is smaller than specified size for example). Note that original image is still retained as is. If you need to actually … Read more

Is it possible to pull and display a single landscape oriented image

Function to retrieve “landscape” oriented image function wpse_96012_landscape_image() { /* global post object holding info about the current post */ global $post; /* grab all images attached to the current post */ $attached_images = get_children( array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’ ) ); /* set minimum ratio between width / height, … Read more

File format of post image attachment

$post_thumbnail_id = get_post_thumbnail_id(); $thumb = get_post($post_thumbnail_id); var_dump($thumb); Look at the post_mime_type in the $thumb object. Reference http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail http://codex.wordpress.org/Function_Reference/get_post

Get uploaded image path in wordpress by filename

I am not 100% sure I understand what you want but… WordPress treats attached media like a custom post type. The file name, minus the extension, is stored as the post_title in the $wpdb->posts table. So, to get the path just search for the file name minus the extension. $q = new WP_Query( array( ‘fields’ … Read more

how to replace embedded “full” sized images within a post with the “large” ones

I solved my own problem by using the creating a page using the following template. Just create and visit the page using the template below. You will only be viewing the results with primitive pagination, follow the code and it’s easy. Changes will not be saved until you visit /whatever-permalink-you-have/?updating=true Caution Please backup your database … Read more

Populate a slideshow list of images from images in a wordpress page?

Most of this is part of the Codex: <?php $attachments = get_posts(array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ =>’any’, // This is where you specify the ID of your private image page ‘post_parent’ => $private_page_id, )); if (count($attachments)) { // We have attachments ?> <ul id=”flexiselDemo3″> <?php // Now we loop through them foreach … Read more

Confusion about arguments sent to add_image_size

As @PieterGoosen said, your point is valid. A look into the source confirms that the codex description of add_image_size was wrong there. It was, because I changed it to be correct. That said, everyone can help improving the codex, you just need to register. You might want to take a look at Contributing to WordPress … Read more