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

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

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

add the post as canonical for attachment page wordpress

Here’s an (untested) example where we inject into the header tag on attachment’s pages, the canonical link of the attached post: add_action( ‘wp_head’, ‘wpse_attachment_parent_canonical’ ); function wpse_attachment_parent_canonical() { // Only target attachment’s pages if( ! is_attachment() ) return; $object = get_queried_object(); // Make sure we’re dealing with a WP_Post object if ( ! is_a( $object, … Read more

Use Gravatar as fallback image if no local image is not found

You can use the get_avatar_url filter (see the arguments passed here in the source code) to change the avatar url and then simply use get_avatar() with the user email in the theme as you’re used to. add_filter(‘get_avatar_url’, ‘wpse_avatar_or_gravatar’, 10, 3); function wpse_avatar_or_gravatar($url, $id_or_email, $args) { // was id passed via $id_or_email if ($id_or_email == intval($id_or_email)) … Read more

Get full URL of images in media library including http://

I’m sure some plugin or your theme modifies your attachment url. Try to find wp_get_attachment_url hook in your code or simply create your own with high priority this way: add_filter(‘wp_get_attachment_url’, function($url) { return preg_replace(“~^//(.+)$~”, “https://$1”, $url); }, 999); or better: add_filter(‘wp_get_attachment_url’, function($url) { return set_url_scheme($url, ‘https’); }, 999); But I recommend you to find the … Read more

Question about add_image_size()

First, let’s check the behavior of cropping. According to code reference: If false (default), images will be scaled, not cropped. If an array in the form of array( x_crop_position, y_crop_position ): x_crop_position accepts left, center, or right. y_crop_position accepts top, center, or bottom. Images will be cropped to the specified dimensions within the defined crop … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)