admin管理员组

文章数量:1394184

In my template i'm using a link for downloading a file (probably a PDF or a JPEG) that I will upload from Media Library. How can I get the url path for this specific file? What template tag I have to use?

Thanks

In my template i'm using a link for downloading a file (probably a PDF or a JPEG) that I will upload from Media Library. How can I get the url path for this specific file? What template tag I have to use?

Thanks

Share Improve this question asked Mar 3, 2020 at 18:04 Antonino LatteneAntonino Lattene 1431 gold badge2 silver badges12 bronze badges 6
  • How is the file connected to the page/post in the template? How do you tell it apart from all the other files – Tom J Nowell Commented Mar 3, 2020 at 18:43
  • I'm not sure what you mean.. I need to have this link in the home (front-page.php). Is that what you meen? – Antonino Lattene Commented Mar 3, 2020 at 20:04
  • This one will get you the media-url from the unique-id of the media-item developer.wordpress/reference/functions/… – admcfajn Commented Mar 3, 2020 at 21:19
  • I mean if you want to show a file you've uploaded in a place, you need to know its ID and have that stored somewhere, but if all you've done is go to the media section and uploaded it, how do we know which file you meant to display? Have you considered just having a page as your front page, and using a file block? Or inserting an attachment into the page as a link? – Tom J Nowell Commented Mar 3, 2020 at 21:56
  • Maybe I am a bit confused about how to get it.. Let me give you more context...I just want to have a link in my home page, so when users click on it they will download my CV... I thought i needed to upload it by Media Library and then get the URL through some template tag and put it in my page.. This is not the right way to do it? – Antonino Lattene Commented Mar 3, 2020 at 23:50
 |  Show 1 more comment

3 Answers 3

Reset to default 0

All uploads to Media Library have their link saved. Click on the image, find the Details Section. Click on More Details.

you should create custom field and place media url in that, call custom fields in home page by code. Reference URL: https://www.wpbeginner/wp-tutorials/wordpress-custom-fields-101-tips-tricks-and-hacks/

I think that the best way is to upload the file in a separate folder from media library and then call it by using get_stylesheet_directory_uri();

For example: dist/img/cv.pdf">

本文标签: linksHow can I get the url from file uploaded in Media Library