I am using the code below to give users download the thumbnail image, as i have a wallpapers site:

<a class="downloadbutton" href="<?php echo $src[0]; ?>" download="imageName">Download this Wallpaper</a>

But the above code is giving download of a htm file not the image download, can anyone please help me solve this. Thank you

  • Please clarify. You want to link a thumbnail/featured image to a file which users can download? Or you want to add a link to a file which is a image? – Brad Dalton Jan 4 '14 at 17:57
  • i want to download the thumbnail and i m using this function in my custom post type, and yes it is an image .jpg – user2252314 Jan 4 '14 at 17:58
  • close voting as if the file being opened is an html, either the link is not to an image or there is some sever configuration problem – Mark Kaplun Sep 13 '16 at 7:09

Upload the file to your Media Library and link to it using HTML anywhere in your theme.

<a href="http://www.example.dev/wp-content/uploads/2014/01/logo.jpg">Download this image</a>

your code seems ok, but make sure the $src[0] is giving the full url to the image as:"http://www.yoursite.com/your_upload_folder/imagename.jpg" with extension

check the value of the $src[0] to make sure it's giving the full url to the image and your code will work.

$thumbnailSrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false );
<a download="<?php the_title(); ?>" href="<?php echo $thumbnailSrc[0]; ?>"><?php the_title(); ?></a>

Use this in your archive file.

  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Oct 15 '17 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.