Archived topic
Customizing Attachment Pages
12 replies · Started by Vish on July 8, 2019
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
Hi 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 to after_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 :)
Thanks, Tom, that worked like a charm! :)
Awesome, glad I could help :)
Hey I Ma Adding Download Code In Hook But When I Click Download Bottom Then Open New Tab
If you don't want it to open in a new tab, remove this part of the code: target="_blank"
?php
$attachment_url = wp_get_attachment_url( get_the_ID() );
?>
Hey I AM Removing " target="_blank" from code but bottom not working
Hi there,
can you raise a new topic where you can share a link to your site so we can take a look.
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 button
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/
Hi Manish,
I've checked your site and the target="_blank" attribute on download link is still there.
https://share.getcloudapp.com/7KuPrDje
You really have to remove that so the browser doesn't open a new tab for it.
THE BUTTON DOES NOT WORK When I Remove TaRGET BLANK
THE BUTTON DOES NOT WORK When I Remove TaRGET BLANK
Can you keep it removed and let us check?