Remove default Image Sizes

To unset all default image sizes in WordPress using PHP you can use this function: add_filter( ‘intermediate_image_sizes’, ‘remove_default_img_sizes’, 10, 1); function remove_default_img_sizes( $sizes ) { $targets = [‘thumbnail’, ‘medium’, ‘medium_large’, ‘large’, ‘1536×1536’, ‘2048×2048’]; foreach($sizes as $size_index=>$size) { if(in_array($size, $targets)) { unset($sizes[$size_index]); } } return $sizes; } Alternatively, you can also unset default images by going … Read more

image_size with respect to aspect ratios

Right before image subsizes are created, there’s a filter called intermediate_image_sizes_advanced that lets you modify the list of sizes. Here’s code that you could expand on — right now it just removes the thumbnail as a proof of concept: function remove_image_sizes_before_generation( $new_sizes, $image_meta, $attachment_id ) { $width = $image_meta[0]; $height = $image_meta[1]; // … Calculate aspect … Read more

How to automatically convert images to WebP on WordPress?

Doing this in vanilla WordPress using hooks requires code that hasn’t been released yet, specifically: https://core.trac.wordpress.org/changeset/53751 https://core.trac.wordpress.org/ticket/55443 That Trac ticket adds new filters which are available in WordPress 6.1. Note that if your server cannot process webp images for resizing then webp will not work for you even with these filters. You will need to … Read more

WordPress can’t get image url but both the attachment and the actual file are there

Not sure how you’re using it, but wp_get_attachment_image_src() returns an array. This should work: <?php $attachmentID = 519271; $imageSizeName = “thumbnail”; $img = wp_get_attachment_image_src($attachmentID, $imageSizeName); ?> <img src=”<?php echo $img[0]; ?>” alt=”image”> An alternative to try if it isn’t working: <img src=”<?php echo wp_get_attachment_url(519271); ?>” alt=”image”> This thread discusses your issue further: wp_get_attachment_image_src always returns … Read more

Get content from one WordPress website to another

If you have access to the old WordPress site go into the admin section then > Tools > Export. Where it says Choose what to export check All content, and click Download Export file. In the new WordPress site go into the admin section > Tools > Import > choose WordPress form the list (it … Read more

Why is the image in div not displayed in full-size?

Just a guess, but img probably does not have a child element with the class size-full. The class is probably on the img itself. So it should probably be img.size-full without a space. Which would make this a CSS problem and not a WordPress problem.

How to show file type of featured image?

If you want to show the File type of featured image. then try the below code. <?php $id1 = get_post_thumbnail_id($post->ID); $type = get_post_mime_type( $id1 ); $mime_type = explode(“https://wordpress.stackexchange.com/”, $type); $type=”.”.$mime_type[‘1’]; echo $type; ?> It will display the exact extension that you want “.jpeg” from “image/jpeg” Here “$post->ID” is current post id (or the id of … Read more

How to get the attribues (alt and title) of an image import with ACF [closed]

It’s already in the docs. Try this: <?php $image = get_field(‘image’); if( !empty($image) ): ?> <img src=”https://wordpress.stackexchange.com/questions/223867/<?php echo $image[“url’]; ?>” alt=”https://wordpress.stackexchange.com/questions/223867/<?php echo $image[“alt’]; ?>” /> <?php endif; ?> For easier debugging, try this: var_dump($image); to print out the $image variable to know what is in $image. You can also put var_dump($image) inside <pre> tag for … Read more