0

I want to add download button for featured image in every post automatically in WordPress with the usage of php files. I don't want to use shortcodes, custom html in every post or plugins, cause I need automated, simple and reliable solution.

This is my code showing featured image in the single post content page.

<div <?php post_class( 'inside item' ); ?>>
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'post-page', array( 'class' => 'featured-image' ) ); ?></a>

Underneath I would like to add a button to download this particular image:

<a class="download_image" href="<?php featured-image-link?; ?>"
>Download this Image</a>

But I don't know how to provide an automatic link to the photo in its full size (which can be seen above).

Thanks for all your suggestions and comments!

0

You can use the_post_thumbnail_url(); to get the thumbnail URL. More infos about the function: https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

<a class="download_image" href="<?php the_post_thumbnail_url( 'full' ); ?>">Download this Image</a>
| improve this answer | |
  • Thank you! I will try to play with it a little bit! Will be back soon. – Mary Mar 20 '16 at 15:29
  • Okay, It works for me just fine. I just add some code for it to force the download, not open in the browser. I'll drop it here for others: "<a class="download_image" href="<?php the_post_thumbnail_url( 'full' ); ?>" download>Download this Image</a>". Thank you once again! – Mary Mar 20 '16 at 15:43

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