Use Exact Image Size using add_image_size

At last I’ve fixed the issue. In my parent theme, the dev have used the following code

if ( ! isset( $content_width ) )
{
    $content_width = 650;
}

which means if the value of $content_width has not set up yet then set it to 650. Now in my chield theme at the time of overwriting and mentioning image type I’ve just added few more lines like this:

function img_update() {
    global $content_width;

    if ( isset( $content_width ) )
    {
        $content_width = 740;
    }

    if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'blog_feat_img', 720 );
        add_image_size( 'latest_posts_widget_feat_img', 400 );
        add_image_size( 'portfolio_widget_feat_img_1x', 400 );
        add_image_size( 'portfolio_widget_feat_img_2x', 800 );
        add_image_size( 'blog_body_img', 740 );
    }
}
add_action( 'after_setup_theme', 'img_update', 11 );

This type I have checked if the value of $content_width has already been set. Which is virtuosos because my function in priority 11 so the parent theme func with first set the value then I overwrite it.

Every thing is fine now.

Previous

wrong image width

Now

everything is ok

Leave a Comment