Is there a hook which fires after all thumbnails are generated?

Thumbnails in WordPress can be generated by using wp_generate_attachment_metadata(), this function fires a filter after generating all the thumbnails wp_generate_attachment_metadata and the filter provides $metadata and $attachment_id to the hooked functions. You can hook your custom function to this filter. $metadata : Attachment metadata. What you need is $metadata[‘sizes’][‘<size-name>’], the <size-name> is the name of … Read more

get_post_gallery with Gutenberg

Using birgire’s suggestions, I came up with the following solution that is working well with both the old pre-WP 4.x data and the newer posts that have been added under 5.0. // if there is a gallery block do this if (has_block(‘gallery’, $post->post_content)) { $post_blocks = parse_blocks($post->post_content); $ids = $post_blocks[0][attrs][ids]; } // if there is … Read more

What’s the proper way to find and remove duplicate images from posts and the media library?

combining the two answer on this page, I found this worked. $args = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 )); $loop = new WP_Query($args); while($loop->have_posts()) { the_post(); $args2 = array( ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’); $attachments = get_posts($args2); if($attachments) { foreach ($attachments as $img_post) { if( … Read more

Why WordPress automatic cropping all my images?

WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media): Thumbnail (typically 150px × 150px) Medium (typically 300px × 300px) Large (typically 1024px × 1024px) It’s to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files- The … Read more

Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords

I have tested this with an image I created myself with Photoshop where I inserted the word “Süss” in every thinkable IPTC field. I uploaded it to my WordPress 4.6 installation, which has no image handling plugins installed. The uploading went smoothly, the right thumbnails were created in the uploads directory and the caption field … Read more

How to insert pictures without hard coded dimensions?

I don’t know if this is the best way to do this, but it works for me. In the functions.php of the theme you are using, put this: function remove_img_src($html) { $html = preg_replace(‘@(width|height)=”([0-9])+” ?@i’, ”, $html); return $html; } add_filter(‘image_send_to_editor’, ‘remove_img_src’, 10, 8); It uses regular expresions to change the output that is inserted … Read more

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