I’m trying to control the output of the random image within this bit of code. The end goal is to NOT output the width
and height
attributes for the image.
I want this:
<img src="URL HERE" alt="ALT HERE"/>
BUT I DON’T WANT THIS (which is what the code below currently outputs):
<img src="URL HERE" alt="ALT HERE" width="200px" height="200px" />
My code:
$thumb_id = get_post_thumbnail_id(get_the_ID());
$args = array(
'order' => 'ASC',
'orderby' => 'rand',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => 1,
'exclude' => $thumb_id
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo wp_get_attachment_image($attachment->ID, 'full', false);
}
}
Use
wp_get_attachment_image_src()
and build a simplifiedimg
element. You may use something like the following code as a replacement forwp_get_attachment_image()
:Put the function above into your theme’s
functions.php
. Call it likewp_get_attachment_image()
: