Echoed image URL has '/'s replaced with '"=" 's
-
I’ve written a shortcode that inserts a summary of a defined post or page including an image attached to the said post or page. It works, except when it comes to the div box containing the image, the image url is returned with spaces & quotation marks instead of forward slashes (i.e.
https://example.com/subdirectory/image.jpg
is returned ashttp:="" example.com="" subdirectory="" image.jpg=""
)Here is the relevant bit of code:
`$attachments = get_children( array(
‘numberposts’ => 1,
‘order’=> ‘DESC’,
‘orderby’ => ‘Description’,
‘post_mime_type’ => ‘image’,
‘post_parent’ => $id,
‘post_status’ => null,
‘post_type’ => ‘attachment’
));
if ($attachments) {
foreach($attachments as $attachment) {
$image_attributes = wp_get_attachment_image_src( $attachment->ID, ‘medium’ );
echo ‘<div style=”background-image: url(“‘,”$image_attributes[0]”,'” class=”filled”></div>’;
}
}`…which returns the following:
<div style="background-image: url(" http:="" example.com="" subdirectory="" wp-content="" uploads="" 2012="" 11="" our-selection-282x300.jpg"="" class="filled"></div>
Does anyone know why this is?
Thanks in advance
- The topic ‘Echoed image URL has '/'s replaced with '"=" 's’ is closed to new replies.