• Hi all

    I’ve created a function to place a random thumbnail image on a page of a client’s website. The function looks like:

    function inspired_by_image ($size='thumbnail')
    {
    	$attachments =& get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'rand'));
    	if (!empty($attachments)) {
    		$first_attachment = array_shift($attachments);
    	}
    
    	echo wp_get_attachment_image($first_attachment->ID, $size);
    
    }

    It’s working fine, excerpt for that the client would like to add an _external_ link to the image, as opposed to linking to the image itself – e.g. the image links to https://www.google.com.

    I noticed the Link URL field in the image uploader section ignores manually typed in links that are not on the site. Do i need to create a separate field in the database to pull this off?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using wp_get_attachment_image for thumbnails and external link’ is closed to new replies.