Unable to get custom WordPress image size

I defined my custom image sizes as follows:

add_theme_support('post-thumbnails'); add_image_size('news-big', 370, 240, true); add_image_size('news-small',270,150,true); add_image_size('portfolio-big',370,500,true); add_image_size('portfolio-small',270,350,true); add_image_size('client',200,150,false); 

I uploaded test photos and it works - they are changed. But when I try to print it:

  <?php $img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID, 'news-big') ); ?> <?php print_r($img); ?> 

It returns the thumb (150x150). The first time I see something like this. I use the Roots frame theme. What's wrong?

+6
source share
3 answers

You have an inappropriate bracket, so in fact you did not pass the size of wp_get_attachment_image_src , and by default it was a thumbnail.

 <?php $img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'news-big' ); ?> 
+9
source

get_post_thumbnail_id accepts only one argument, post id ...

Do you want to pass the size argument to wp_get_attachment_image_src

 $img_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), news-big' ); 

Why?

Despite the fact that WordPress makes a lot of images according to your size definitions, there is still only one attachment identifier. There are no different identifiers for different sizes.

+2
source

This is the wrong thumdnail mapping:

 <?php $img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID, 'news-big') ); ?> <?php print_r($img); ?> 

If u add thumnail for publication, you can just use:

 the_post_thumbnail(); 

without it, everything else. And if you add the custom thumbnail size, you can use:

 the_post_thumbnail('news-big'); 

But before using it, he really needs to add an image for publication as "Best Image."

0
source

All Articles