- This topic has 12 replies, 4 voices, and was last updated 4 years, 11 months ago by
Elvin.
-
AuthorPosts
-
July 8, 2019 at 8:29 am #952150
Vish
Hi Tom
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.
Thanks
July 8, 2019 at 3:52 pm #952463Tom
Lead DeveloperLead DeveloperHi there,
I’m not sure how to initiate the download automatically, but it should be easy to add a button.
For example:
1. Create a new Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook toafter_content
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 #963050Tom
Lead DeveloperLead DeveloperAwesome, glad I could help 🙂
March 7, 2021 at 9:21 am #1685699Manish
Hey I Ma Adding Download Code In Hook But When I Click Download Bottom Then Open New Tab
March 8, 2021 at 8:54 am #1686968Tom
Lead DeveloperLead DeveloperIf you don’t want it to open in a new tab, remove this part of the code:
target="_blank"March 15, 2021 at 7:37 am #1696113Manish
?php
$attachment_url = wp_get_attachment_url( get_the_ID() );
?>Hey I AM Removing ” target=”_blank” from code but bottom not working
March 15, 2021 at 7:55 am #1696137David
StaffCustomer SupportHi there,
can you raise a new topic where you can share a link to your site so we can take a look.
May 10, 2021 at 11:09 am #1773158Manish
Hey, This Is My Website Attachment Url -https://pt.oyepng.com/leao-zangado-png-imagens-baixar-11/
Screenshot- https://prnt.sc/12rtwvn
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 #1773483Elvin
StaffCustomer SupportHi Manish,
I’ve checked your site and the
target="_blank"attribute on download link is still there.
https://share.getcloudapp.com/7KuPrDjeYou really have to remove that so the browser doesn’t open a new tab for it.
May 11, 2021 at 11:15 am #1774780Manish
THE BUTTON DOES NOT WORK When I Remove TaRGET BLANK
May 11, 2021 at 7:58 pm #1775103Elvin
StaffCustomer SupportTHE BUTTON DOES NOT WORK When I Remove TaRGET BLANK
Can you keep it removed and let us check?
-
AuthorPosts
- You must be logged in to reply to this topic.