Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGonzaloº Caminos
2,231 Pointsarray $size not working in wp_get_attachment_image_src function
Hi. I am adapting the code from Bootstap to WordPress i want use array $size in function wp_get_attachment_image_src but this function only works with "thumbnail" and not with my values.
<?php
$thumbnail_id = get_post_thumbnail_id();
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, array('250', '300'), true );
?>
Don't work.
<?php
$thumbnail_id = get_post_thumbnail_id();
$size = array('width'=>250,'heith'=>250);
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, $size, true );
?>
Don't work.
2 Answers
Muhammad Ehsan Hanif
8,236 PointsYou can use the add image size function in your functions.php file like this.
add_action( 'after_setup_theme', 'wpdocs_theme_setup' );
function wpdocs_theme_setup() {
add_image_size( 'category-thumb', 300 ); // 300 pixels wide (and unlimited height)
add_image_size( 'homepage-thumb', 250, 250, true ); // (cropped)
}
and then use it in theme file with the code below.
wp_get_attachment_image_src( $thumbnail_id, 'category-thumb' );
Reference: https://developer.wordpress.org/reference/functions/add_image_size/
Gonzaloº Caminos
2,231 PointsThanks.
Gonzaloº Caminos
2,231 PointsGonzaloº Caminos
2,231 PointsIm triyng to make this modification because i need images with the same size and not this:
http://imgur.com/a/GmDbF