How Do I Delete All The Images from WordPress

You could try the following, I havent tested it, so look out for typos or errors: $all_posts = get_posts(array( ‘numberposts’ => – 1, ‘post_status’ => ‘any’, ‘post_type’ => get_post_types(”, ‘names’) , )); foreach($all_posts as $all_post) { delete_post_media($all_post->ID); } function delete_post_media($post_id) { if (!isset($post_id)) return; elseif ($post_id == 0) return; elseif (is_array($post_id)) return; else { $attachments … Read more

limit file type and file size using media_handle_upload

Use PHP // Check that the nonce is valid, and the user can edit this post. if (isset( $_POST[‘my_image_upload_nonce’] ) && wp_verify_nonce( $_POST[‘my_image_upload_nonce’], ‘my_image_upload’ ) ){ // Input type file name $image_input_name=”my_image_upload”; // Allowed image types $allowed_image_types = array(‘image/jpeg’,’image/png’); // Maximum size in bytes $max_image_size = 1000 * 1000; // 1 MB (approx) // Check … Read more

Display post image with fancybox

When you echo something, you need to be echoing the variable. You are using the_post_thumbnail_url, which in itself is already an echo statement. You should be using get_the_post_thumbnail_url instead. echo “<a class=”fancybox” rel=”group” href=”” . get_the_post_thumbnail_url( get_the_ID(), “full’ ) . “‘>”; EDIT: Also, missing the $post_id, fixed to include it in the function

Add Small Image Size to Media Settings

You can register a new image size by using add_image_size() add_image_size( string $name, int $width, int $height, bool|array $crop = false ) Parameters $name (string) (Required) Image size identifier. $width (int) (Required) Image width in pixels. $height (int) (Required) Image height in pixels. $crop (bool|array) (Optional) Whether to crop images to specified width and height … Read more

How to get image ID to use inside wp_read_image_metadata()?

I would like to automatically set the alternative text to be the same as the title of a post when image is uploaded. The attachment’s image alternative text is stored in the post meta table under the _wp_attachment_image_alt meta key. In media_handle_upload() and media_handle_sideload() we have: $id = wp_insert_attachment($attachment, $file, $post_id); if ( !is_wp_error($id) ) … Read more

Auto crop images in WordPress

You can use add_image_size to create your custom size like this: add_image_size( ‘featured-works’, 220, 180, true ); then get it like this: wp_get_attachment_image_src($thumbnail_id,’featured-works’); take into account how the crop works here

how to add an image to the footer?

Sounds like several different pointers may be useful: Are you working on a theme that was custom developed for your website? If not, you should create a child theme so that anytime the parent theme receives an update, your changes won’t be overwritten. The image you’re trying to add should either be uploaded through WordPress’s … Read more

Get an image’s alt text in a shortcode using the image URL

Instead of using the locationimage attribute, why not use the attachment ID? This will allow you to dynamically grab the URL to the file and will make getting other meta data such as the alt text much easier. Below is a rewritten version of hplocationsfn(). Usage example: [hpLocationSquare id=’2299′ link=’http://example.com’] Note that the link attribute … Read more

Add attribute to caption shortcode from custom attachment field

Here’s a solution that leverages the shortcode_atts_{shortcode} filter, where caption is the shortcode in this case. This works by pulling the attachment id from $out[‘id’] then getting the value of the class via get_post_meta( $attachment_id, ‘img_class_field’, true ). With this approach, it is not necessary to modify the output of the caption shortcode in the … Read more