How to retrieve custom thumbnail dimensions in WordPress using get_the_post_thumbnail?

I’m having trouble getting the right image size when using WordPress thumbnail functions. In my theme’s functions.php file, I’ve configured a custom featured image size like this:

if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    set_post_thumbnail_size(800, 600, true); // custom thumbnail size with cropping
}

However, when I try to display the image using this code:

echo get_the_post_thumbnail($article->ID, array(800, 600), array('class' => 'responsive-img'));

The output image always shows up as 150x150 or the full original size instead of my desired 800x600 dimensions. I’ve tried clearing cache and regenerating thumbnails but still get the wrong size. What am I missing here? How can I properly fetch the custom thumbnail size I defined in functions.php?

you’re confusing how wordpress handles image sizes. set_post_thumbnail_size() creates the size, but you can’t just pass arrays directly to get_the_post_thumbnail(). use get_the_post_thumbnail($article->ID) without the array - it’ll automatically use your 800x600 setting. arrays only work with registered size names, not raw dimensions.

I hit this exact issue building a portfolio site last year. Here’s what’s happening: set_post_thumbnail_size() and passing array dimensions to get_the_post_thumbnail() don’t work the way you’d think. WordPress won’t create image sizes on-the-fly from arrays - it only uses registered sizes you’ve already defined. Your set_post_thumbnail_size(800, 600, true) creates a size called ‘post-thumbnail’, but when you pass array(800, 600) directly, WordPress looks for an existing registered size with those exact dimensions. Can’t find one? It defaults to something else. Fix: use the registered size name instead: echo get_the_post_thumbnail($article->ID, 'post-thumbnail', array('class' => 'responsive-img'));. This’ll actually use your 800x600 dimensions. Don’t forget to regenerate thumbnails for existing images after adding the size definition.

The issue arises because set_post_thumbnail_size() only sets default dimensions for the_post_thumbnail() when no parameters are passed. When you specify dimensions in an array to get_the_post_thumbnail(), WordPress searches for a predefined image size matching those exact dimensions. If none exists, it resorts to a default size instead. To resolve this, you should define a named image size using add_image_size(), like this: add_image_size('custom-featured', 800, 600, true);. Then, you can call it by name with echo get_the_post_thumbnail($article->ID, 'custom-featured', array('class' => 'responsive-img'));. Ensure to regenerate thumbnails with a plugin like ‘Regenerate Thumbnails’ if you want older images updated to the new size.