Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image_default_size doesn't change in wordpress

I'd like to change the default size for images within posts. I've tried to edit both the /wp-admin/options.php page and the functions.php file, but none affect the size. They do work for the default alignment and the default link, but not for the size.

Here's the snippet from my functions.php file

    add_action( 'after_setup_theme', 'default_attachment_display_settings' );

function default_attachment_display_settings() {
 update_option( 'image_default_align', 'right' );
 update_option( 'image_default_size', 'large' );
}

The images keep showing up as "full size".

like image 846
Ivano Avatar asked Dec 31 '25 01:12

Ivano


1 Answers

That option seems to be ignored by the editor, but this works:

add_action( 'admin_head-post.php', '_my_reset_image_insert_settings' );
add_action( 'admin_head-post-new.php', '_my_reset_image_insert_settings' );
function _my_reset_image_insert_settings() {
  ?>
    <script>
      if ( typeof setUserSetting !== 'undefined' ) {
        //setUserSetting( 'align', 'none' ); // none || left || center || right
        setUserSetting( 'imgsize', 'large' ); // thumbnail || medium || large || full
        //setUserSetting( 'urlbutton', 'none' ); // none || file || post
      }
    </script>
  <?php
}

Snippet made by @azaozz Source: https://core.trac.wordpress.org/ticket/35101#comment:15

like image 152
Michael Rogers Avatar answered Jan 01 '26 18:01

Michael Rogers