I have some hooks on my WordPress Theme in order to customize the default images sizes, but it does not work. Here is the code:

function my_custom_image_size() {
    add_image_size( 'post_size', 730);
add_action( 'after_setup_theme', 'my_custom_image_size' );

// Cambia el nombre del tamano de imagen
function my_custom_image_size_name( $sizes ) {
    return array_merge( $sizes, array(
        'post_size' => __( 'Tamaño Post' ),
    ) );
add_filter( 'image_size_names_choose', 'my_custom_image_size_name' );

function my_default_image_size() {
    update_option('image_default_size', 'post_size');
    update_option('image_default_align', 'right');
add_action('after_setup_theme', 'my_default_image_size');

function my_remove_default_images( $sizes ) {
    unset($sizes['thumbnail']); // disable thumbnail size 
    unset($sizes['medium']); // disable medium size 
    unset($sizes['large']); // disable large size 
    unset($sizes['medium_large']); // disable medium-large size 
    unset($sizes['1536x1536']); // disable 2x medium-large size 
    unset($sizes['2048x2048']); // disable 2x large size return $sizes;
    return $sizes;
add_filter( 'intermediate_image_sizes_advanced', 'my_remove_default_images' );

Everything works fine but the function "my_default_image_size" does not work I don't know why. Any of these lines of code works:

update_option('image_default_size', 'post_size');
update_option('image_default_align', 'right');

When I go to a new post, the default image size is full-size and the default alignment is center. It seems a bug on "image_default_size" and "image_default_align"

When I add a new image in the sidebar appears like that:

Default option, Fullsize


Could anyone help me? Thanks!

1 Answer 1


My guess is that there are spaces at the end of the option names:

update_option('image_default_size ', 'post_size');
update_option('image_default_align ', 'right');

it should be:

update_option('image_default_size', 'post_size');
update_option('image_default_align', 'right');
  • Hi rugbert, thanks for your answer. Onfortunately it was a mistake but I fixe it and the problem continues. I am thinking about the image_default_size works only with default size names... thumbnail, medium, large, etc... But... the image_default_align it should work.
    – etamarit
    May 27, 2020 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.