kisukedeath

wp_get_attachment_image_src size & custom size

Jul 21st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. wp_get_attachment_image_src() accepts built-in sizes such as thumbnail, medium, large or full.
  2.  
  3. // copied from the Codex
  4. // https://codex.wordpress.org/Function_Reference/add_image_size
  5. if ( function_exists( 'add_image_size' ) ) {
  6.     add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
  7.     add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped)
  8. }
  9.  
  10. $image_attributes = wp_get_attachment_image_src( 28, 'category-thumb' );
  11. var_dump($image_attributes);
  12.  
  13. You will notice that the image returned is (an appromixation of) 300x9999-- that is 300 wide by whatever height scales correctly.
Advertisement
Add Comment
Please, Sign In to add comment