Block Editor PHP Beginner

Set the Default Size for New Image Blocks

Make new Image blocks use the Large size (or any registered size) instead of the full-size original.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 4 lines
add_filter( 'block_editor_settings_all', function ( array $settings ): array {
	$settings['imageDefaultSize'] = 'large';
	return $settings;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

New Image blocks insert the size set under Settings → Media, which is often the full-size original. Multi-megabyte photos then load on every page. This snippet makes the editor choose a smaller size by default.

How it works

The block editor reads imageDefaultSize from its settings when an image is added. Setting it to 'large' means new Image blocks use the Large size. Editors can still pick another size in the block sidebar.

Things to watch

  • Use any registered size name, such as 'medium' or a custom size from your theme.
  • Images already in posts don’t change.

How to test it

Add an Image block and upload a photo. In the sidebar, Resolution should show Large.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only