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="https://wordpress.stackexchange.com/questions/255020/<?php echo wp_get_attachment_url( 2582 ); ?>" title="Download Portfolio">Download My Portfolio</a>
</div>
</div>
Any Ideas?
Grts,
Nanou
1 Answer
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.
<?php
$attachment_id = 2582;
$attachment_page = get_attachment_link( $attachment_id );
?>
<a href="https://wordpress.stackexchange.com/questions/255020/<?php echo $attachment_page; ?>"><?php echo get_the_title($attachment_id ); ?></a>