- This topic has 12 replies, 4 voices, and was last updated 1 month ago by Elvin.
July 8, 2019 at 8:29 am #952150Vish
I want the below customization for the attachment pages:
1. Clicking on the attachment (for example image) opens it in new page. How can I force to download it? For example, when a user clicks on the image in the attachment page, it should start downloading.
2. I want to display a button (or simply a link, which can be customized via CSS to look like a button) below the attachment (only in the attachment page) which points to the same link as the attachment. This button or link, will also start downloading the attachment upon clicking. How can I do this?
Any help on this would be great.
ThanksJuly 8, 2019 at 3:52 pm #952463TomLead DeveloperLead Developer
I’m not sure how to initiate the download automatically, but it should be easy to add a button.
1. Create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook to
3. Check the “Execute PHP” option
4. Set this as your hook content:
<?php $attachment_url = wp_get_attachment_url( get_the_ID() ); ?> <a class="button" href="<?php echo $attachment_url; ?>" target="_blank">Download</a>
5. Set the Display Rules to “Media -> All Media”
That should do it 🙂July 20, 2019 at 1:53 pm #962953Vish
Thanks, Tom, that worked like a charm! 🙂July 20, 2019 at 6:46 pm #963050TomLead DeveloperLead DeveloperMarch 7, 2021 at 9:21 am #1685699Manish
Hey I Ma Adding Download Code In Hook But When I Click Download Bottom Then Open New TabMarch 8, 2021 at 8:54 am #1686968TomLead DeveloperLead DeveloperMarch 15, 2021 at 7:37 am #1696113Manish
$attachment_url = wp_get_attachment_url( get_the_ID() );
Hey I AM Removing ” target=”_blank” from code but bottom not workingMarch 15, 2021 at 7:55 am #1696137DavidStaffCustomer SupportMay 10, 2021 at 11:09 am #1773158Manish
Hey, This Is My Website Attachment Url -https://pt.oyepng.com/leao-zangado-png-imagens-baixar-11/
When I Click On Download Button Then Images Open New Tap Can
And Can You Tell me how can l centre buttonMay 10, 2021 at 11:11 am #1773162Manish
Hey Can Anoye One Tell me how can make attachment page like this -https://stockwallpapers.themefoxx.com/xiaomi-mi-11-ultra-stock-wallpapers/xiaomi-mi-11-ultra-stock-wallpapers-3/May 10, 2021 at 8:50 pm #1773483ElvinStaffCustomer Support
I’ve checked your site and the
target="_blank"attribute on download link is still there.
You really have to remove that so the browser doesn’t open a new tab for it.
A wise man once said:
"Have you cleared your cache?"May 11, 2021 at 11:15 am #1774780Manish
THE BUTTON DOES NOT WORK When I Remove TaRGET BLANKMay 11, 2021 at 7:58 pm #1775103ElvinStaffCustomer Support
THE BUTTON DOES NOT WORK When I Remove TaRGET BLANK
Can you keep it removed and let us check?
A wise man once said:
"Have you cleared your cache?"
- You must be logged in to reply to this topic.