Codex tools: Log in
Contents |
Returns an array with the image attributes "url", "width" and "height", of an image attachment file.
Note: For just the image src, use the first element in the returned array.
<?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>
or false, if no image is available.
<?php $attachment_id = 8; // attachment ID $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array ?> <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
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 the "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
.
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()