[Resolved] Customizing Attachment Pages

Home Forums Support [Resolved] Customizing Attachment Pages

Home Forums Support Customizing Attachment Pages

  • This topic has 12 replies, 4 voices, and was last updated 1 month ago by Elvin.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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

    #952463
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #962953
    Vish

    Thanks, Tom, that worked like a charm! πŸ™‚

    #963050
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad I could help πŸ™‚

    #1685699
    Manish

    Hey I Ma Adding Download Code In Hook But When I Click Download Bottom Then Open New Tab

    #1686968
    Tom
    Lead Developer
    Lead Developer

    If you don’t want it to open in a new tab, remove this part of the code: target="_blank"

    #1696113
    Manish

    ?php
    $attachment_url = wp_get_attachment_url( get_the_ID() );
    ?>

    >Download

    Hey I AM Removing ” target=”_blank” from code but bottom not working

    #1696137
    David
    Staff
    Customer Support

    Hi there,

    can you raise a new topic where you can share a link to your site so we can take a look.

    #1773158
    Manish

    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

    #1773162
    Manish

    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/

    #1773483
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

    #1774780
    Manish

    THE BUTTON DOES NOT WORK When I Remove TaRGET BLANK

    #1775103
    Elvin
    Staff
    Customer 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?"

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.