Example PHP code:
<?php
$image_attributes = wp_get_attachment_image_src( '8' );
?>
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
Now, lets say, I don’t want to use the $image_attributes variable at all, and directly employ wp_get_attachment_image_src( '8' ); instead of $image_attributes[0];, $image_attributes[1]; and $image_attributes[2]; later on with the img tag.
In that case, how should I modify the code?
WHY?
Let me explain by example (my real use case).
<?php
$attachment_attributes = wp_get_attachment_image_src( '8' ); // returns an array
?>
<media:content url="<?php echo $attachment_attributes[0]; ?>" width="<?php echo $attachment_attributes[1]; ?>" height="<?php echo $attachment_attributes[2]; ?>" type="image/jpeg">
How do I do the same, like when I am coding it like this?
foreach ( $attachments as $att_id => $attachment ) {
$attachment_attributes = wp_get_attachment_image_src( '8' );
// Should it be done like this? If not, how do I do it?
$output .= '<media:content height="' . $attachment_attributes[0]; . '" type="image/jpeg">';
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag}>" . wptexturize($attachment->post_excerpt) . "</{$captiontag}>";
}
$output .= '
</media:content>';
}
Not sure why your trying to avoid variables, but you may be able to get away with something like:
Or, from the code from ‘Why’