0
votes

I just recently migrated some old blog posts from one site to another. The images has been imported as well. However, now most of my images is returning 404 error.

Images are linking to /wp-content/uploads/2018/05/image_name-800x600.jpg at the moment. My issue is that 800x600 is a custom image size that has been added. I've tried to add theme support for 800x600 and then regenerate thumbnails using "force regenerate thumbnails" WordPress plugin. This didn't seem to solve anything.

add_theme_support( 'custom-size' );
add_image_size( 'custom-size', 800, 600 );

I've then tried the force using only default WordPress image sizes:

function remove_extra_image_sizes() {
    foreach ( get_intermediate_image_sizes() as $size ) {
        if ( !in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
            remove_image_size( $size );
        }
    }
}

add_action('init', 'remove_extra_image_sizes');

This works perfectly fines and makes sure that only thumbnail, medium, medium_large and large image sizes is available. However, my images is still returning 404 because of URL in blog posts haven't been updated.

I guess I could do a search & replace using Velvet blue plugin and searching for all images with 404 error. However, I was wondering if there was a smarter way to update all of the URLs since it will take me forever to find all of the 404 image URLs. I've been looking in post_meta in the database etc. in order to see if I could find 800x600 image URL's.

1
Can you post your add_image_size code?Howard E
I've updated question with add_image_size code :)TurboTobias

1 Answers

0
votes

You should add_image_size wrapped in a function and hook to after_theme_setup

add_action('after_setup_theme', 'he_add_image_sizes');
function he_add_image_sizes(){
    add_image_size('custom-size', 800, 600, array( 'center', 'center'));
}

Then regenerate thumbnails. Personally I prefer this plugin. Regenerate Thumbnails this lists all available thumbnail sizes, so you can verify your custom size is actually set.