Hot answers tagged

7

WordPress generates more than 3 thumbnails or image sub sizes because there are actually more than 3 standard/core image sizes in WordPress. Moreover, themes and plugins can also register custom image sizes. :) The 6+1 standard/core image sizes Default (4): Thumbnail, Medium, Large and Medium Large (medium_large), but only the first three that you can ...


5

Since WP 5.3 it is enough to use this function: wp_get_registered_image_subsizes();


4

You could also remove those image sizes completely using remove_image_size (see: https://developer.wordpress.org/reference/functions/remove_image_size/) Example (to be placed in your functions.php file): remove_image_size('1536x1536'); remove_image_size('2048x2048'); This function, however, won't work for default WP image sizes (e.g. 'thumbnail', 'medium', '...


4

What you want to do is already baked into WordPress but just not frequently used. In either the classic or the block editor, click to add an image. Once you have the block upon, instead of uploading or pulling from existing images in your Media Library, click on Insert from URL. Now just paste the URL from wherever the image is being served. Just double ...


3

Wordpress has a hook for that. Here is a sample code: function featured_image_dimensions( $content, $post_id, $thumbnail_id ){ $help_text = '<p>' . __( 'recommended dimensions - H980px by W450px', 'my_domain' ) . '</p>'; return $help_text . $content; } add_filter( 'admin_post_thumbnail_html', 'featured_image_dimensions', 10, 3 ); Add ...


3

Use the render_block filter hook: add_filter( 'render_block', 'wrap_my_gallery_block', 10, 2 ); function wrap_my_gallery_block( $block_content, $block ) { if ( 'core/gallery' !== $block['blockName'] ) { return $block_content; } $return = 'my-gallery-block<div class="my-gallery-block">'; $return .= $block_content; ...


3

If you use WordPress' sideload feature, you can do this more easily (and have WordPress handle all of the sanitization for you). <?php $desc = 'some description'; $file = 'http://www.example.com/image.png'; $file_array = [ 'name' => wp_basename( $file ), 'tmp_name' => download_url( $file ) ]; // If error storing temporarily, return the error. if ( ...


3

Since WP 4.7 you can use wp_get_additional_image_sizes() to get additional image sizes registered (excluding the default image sizes added by WP). Since WP 5.3 you can use wp_get_registered_image_subsizes() to get all the image sizes registered.


3

I tried to replicate your issue and while the dev tools show it as alt the source code shows alt="", so WordPress is not stripping the quotes, it's just the dev tools being concise. But even if it was, they're equivalent so alt and alt="" are the same. As for why the dev tools display alt, it's because the dev tools don't display the HTML,...


2

Update for those finding this all these years later. The function you want is called wp_get_attachment_image_url(). Documentation here. All you need to do is give it the attachment ID and the size and it will return either a string of the image url or false.


2

There's wp_get_attachment_image_url introduced in WordPress 4.4.0. It takes these arguments: int $attachment_id - Image attachment ID. string|array $size - Optional. Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'thumbnail'. bool $icon - Optional. Whether the image should be ...


2

Tomas's answer actually contain's the key to change default linking (for Gutenberg). Does not affect already created galleries. The best way how I was able to implement it, was creating a new edited variation of needed block (gallery), and set it as default. That way the old gallery was replaced by new, edited one. Register new variation by creating js file ...


2

A peek into the WP core file - wp-admin/includes/file.php confirms it is not WP which is doing this. Can you try the following: Check functions.php file in your active theme Try switching to other themes and check if the issue persists Try deactivating all the plugins and then activating them one by one and checking the issue Check your wp-config.php file ...


2

This was (finally) fixed to Gutenberg (and will be applicable for both the image and the gallery blocks); and will add an option to WordPress options' database table. this was done in https://github.com/WordPress/gutenberg/pull/25578 and https://github.com/WordPress/gutenberg/pull/25582 It'll be added to WordPress 5.6 but it's already available in the ...


2

Specifically I would love the idea to allow a short function in PHP living outside my plugin to change it. This is exactly what filters are for. They allow code inside your plugin to call out to anyone else who wants to register a handler function for that filter. You probably have done this with the Wordpress 'system' actions and filters by adding your own ...


2

Found the solution: It can be turned off: add_filter( 'big_image_size_threshold', '__return_false' ); More: here


2

The Latest Posts block uses (wp.data.select( 'core/block-editor' ).getSettings() to get) the image sizes in the editor settings which can be filtered via the block_editor_settings hook in PHP: apply_filters( 'block_editor_settings', array $editor_settings, WP_Post $post ) Filters the settings to pass to the block editor. And the setting name used for the ...


2

Yes, out of the box WordPress stores images and other uploads only as files. Although it could be, theoretically, possible to change this behavior by tapping inton wp_handle_upload() or _wp_handle_upload() and related functions, I think it would be too complex and unreliable. Besides,I think it wouldn't be a good idea for performance reasons in case with too ...


2

TRY THIS,IT MAY HELPFUL Converted to CSV file. uploaded to root folder having column structure as given which contains attachment image ID and alter text run this code for one time only $row = 1; if( ($handle = fopen ( "Book1.csv", "r" )) !== FALSE ) { while ( ($data = fgetcsv ( $handle, 1000, "," )) !== FALSE ) { ...


1

It doesn't, WP supports responsive image markup, so your browser decides based on various factors such as pixel density, battery, network, viewport, etc


1

Images can only be attached to a single post, and they only get attached to the post they were originally uploaded to, and only if it was uploaded to a particular post to begin with. The only way to know if an image is used by a post is to parse the HTML of the posts content and look for its URL.


1

There are a few ways to do this with updates to functions.php as well but the easiest might be to first install Yoast plugin and then use the setting for Attachment URLS that redirect it to the parent post https://yoast.com/media-attachment-urls/


1

So after checking your search.php template, actually the issue is not with WordPress. Instead: That the_post_thumbnail() (as in if ( the_post_thumbnail() )) echoes the post thumbnail and returns nothing which then bypasses your conditional (doesn't echo your img tag), so you should instead use has_post_thumbnail(): if ( has_post_thumbnail() ) { // echo ...


1

It appears that it's eventually used as a parameter to wp_constrain_dimensions where '0' means 'no limit'. It's only used directly in media.php:85 } elseif ( 'medium_large' === $size ) { $max_width = intval( get_option( 'medium_large_size_w' ) ); $max_height = intval( get_option( 'medium_large_size_h' ) ); if ( intval( $content_width ) > 0 ...


1

Your container div for the content area has a class of .row, which is set to display:flex in Bootstrap. Direct children of a parent with display:flex can't be floated. To fix this you'll either need to update the .row class so it's not set to display:flex (display:block works for me), or add an interior wrapper div so that the image and paragraphs not direct ...


1

This can be done using block filters. First, you'll need to filter block attributes for the image block to be able to save the new items: const { addFilter } = wp.hooks; function filterAttributes( settings, name ) { if ( 'core/image' === name && settings.attributes ) { settings.attributes.description = { type: 'string', ...


1

In order for wp_generate_attachment_metadata() to work properly in that it creates a thumbnail and other intermediate/image sizes like medium and large, the image attachment/post data must have the proper MIME type (post_mime_type), and despite you did set it in your $attachment array (the post data), there's a problem with this part in your code: $...


1

If you're using Autoload/Composer you can use $image = \acf_get_attachment( $attachment_id ); to get an acf image array. If not I guess you can use require_once() to load your plugins/advanced-custom-fields-pro/includes/api/api-helpers.php, however I haven't tested this yet.


1

I found a client's site where the filter wasn't working. I did a lot of testing on a sandbox site and the filter worked. The website in question is using the Avada theme. Avada has the threshold size built into the theme settings so you can customize what size you would like the scaled image to be. This was overriding where I was trying turn it off in my ...


1

Try searching for Imagick::setImageFormat, Imagick or setImageFormat in your theme, if you're using free/bought theme, it would be helpful to mention it as @AndrewL64 mentioned


Only top voted, non community-wiki answers of a minimum length are eligible