How to use wp_get_attachment_url in functions.php

For my music archive WordPress theme, I needed to use wp_get_attachment_url in functions.php to grab a url that uses a custom field as follows:

For some reason, WordPress wants to grab the post url rather than the file url. To fix this, I simply had to call the global $post variable as follows:

That’s it! I am sure there is a different/better way to do this, so if you know how to accomplish this a different/better way, please let me know!


Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to and

Follow Toby's contributions on Github and