I have a file called Portfolio.zip in my Media Library which will always have this name.

Now in my page template I need the url to this file. I can achieve this via his id : wp_get_attachment_url( $attachment_id ); but I would like to get the URL by the name "Portfolio.zip" as I know for sure this will always be the same.

My Code:

<div class="row">
    <div class="col-md-12 text-center">
        <a id="download" class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-color-grey"
                    href="<?php echo wp_get_attachment_url( 2582 ); ?>" title="Download Portfolio">Download My Portfolio</a>

Any Ideas?

Grts, Nanou


1 Answer 1


If understand your question correctly, I think this can get the job done. Use get_attachment_link instead of wp_get_attachment_url and then echo the title.

 $attachment_id = 2582;
 $attachment_page = get_attachment_link( $attachment_id ); 
<a href="<?php echo $attachment_page; ?>"><?php echo get_the_title($attachment_id ); ?></a>
  • 1
    Hi thx for answering but I think you misunderstood. I don't need the title. I want the URL but by name and not by id. Commented Feb 3, 2017 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.