[Resolved] Customizing Attachment Pages

Home Forums Support Customizing Attachment Pages

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #952150

    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.


    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:

        $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! 🙂

    Lead Developer
    Lead Developer

    Awesome, glad I could help 🙂

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