Support » Plugins » Hacks » Echoed image URL has '/'s replaced with '"=" 's

  • Matt


    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. is returned as http:="""" 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:="""" subdirectory="" wp-content="" uploads="" 2012="" 11="" our-selection-282x300.jpg"="" class="filled"></div>

    Does anyone know why this is?

    Thanks in advance

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    You should not echo shortcode content. As you have seen, it causes unpredictable behavior. Instead, accumulate output into a variable, then return it from the shortcode function.

Viewing 1 replies (of 1 total)
  • The topic ‘Echoed image URL has '/'s replaced with '"=" 's’ is closed to new replies.