This page redirects to an external site: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
Languages: English • Italiano • 関数リファレンス/wp_get_attachment_image_src 日本語 (Add your language)
Returns an ordered array with values corresponding to the (0) url, (1) width, (2) height, and (3) scale of an image attachment (or an icon representing any attachment).
It's most often used to get the URL (src) for an image attachment: use the first element in the returned array.
wp_get_attachment_image() uses wp_get_attachment_image_src() to fill the width, height, and src attributes of an img.
<?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>
false if no images is found.<?php
$attachment_id = 8; // attachment ID
$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
if( $image_attributes ) {
?>
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>
WordPress can use media icons to represent attachment files on your blog and in the Admin interface, if those icons are available. For images, it returns the thumbnail. For other media types, it looks for image files named by media type (e.g., audio.jpg) in the directory: wp-includes/images/crystal/.
This example shows how you can change this directory to a folder called "images" in your theme: wp-content/themes/yourtheme/images. Create the folder and put "media type images" in there. To tell WordPress the directory has changed, put this in the current theme's functions.php file:
add_filter( 'icon_dir', 'my_theme_icon_directory' );
add_filter( 'icon_dir_uri', 'my_theme_icon_uri' );
function my_theme_icon_directory( $icon_dir ) {
return get_stylesheet_directory() . '/images';
}
function my_theme_icon_uri( $icon_dir ) {
return get_stylesheet_directory_uri() . '/images';
}
find the full code here get_children().
Since: 2.5.0
wp_get_attachment_image_src() is located in wp-includes/media.php.
Attachment Functions:
get_children(), get attached media(), the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()