Support

Account

Home Forums General Issues img src and href not showing up for thumbnails

Solving

img src and href not showing up for thumbnails

  • I’m using the code to call the thumbnail version of one of the images and link through Pretty Photo to the full image. This is the code I have:

    <?php
    
    	$attachment_id = get_field('floorplan_image');
    	$size = "thumbnail";
    	$full_img = wp_get_attachment_image_src( $attachment_id, 'full' );
    	$full_img = $full_img[0];
    
    	echo '<figure><a href="'.$full_img.'" rel="prettyPhoto[pp_gal]">'.wp_get_attachment_image( $attachment_id, $size ).'</a></figure>';
    
    	?>

    And it’s returning this (an empty href and src):`<a rel=”prettyPhoto[pp_gal]” href=””>
    <img src=””>
    </a>`

    I’ve tried uploading the image again, and I’ve tried switching it between Image Object, Image URL, and Image ID… nothing has worked.

    What am I doing wrong?

  • Hi @abitofbrit

    First thing is to test that your data is correct:

    
    <?php 
    
    $attachment_id = get_field('floorplan_image');
    
    echo '<pre>';
    	var_dump( $attachment_id );
    echo '</pre>';
    die;
    
    ?>
    
    What do you get for that debugging?
    
  • When I test the data, I get:

    
    <pre>string(93) "http://website.com/wp-content/uploads/sites/2/2013/09/1b8821.jpg" </pre>

    So it’s definitely recognizing the attachment id (I replaced the website URL with “website.com,” but the string it originally spit out is working.)

  • Hi @abitofbrit

    It is clear that you have selected ‘Image URL’ as the return type. That is why you are getting a string back from the get_field function.

    Your code uses a function called wp_get_attachment_image_src. This function expects to see an ID, not a URL. That is the issue.

    You need to change the return type on the image field to fix the issue.

    Thanks
    E

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘img src and href not showing up for thumbnails’ is closed to new replies.