Get Attachment URL By ID in WordPress

To get the attachment (media) URL by ID in WordPress, first, you need to find the ID. To do this, go to Media and click on the image. In the page URL, you will see the ID in front of the post.

https://honarsystems.com/wp-admin/post.php?post=68&action=edit

In this example, the ID is 68.

Add the ID in function to retrieve the URL for an attachment.

wp_get_attachment_url(68)

You can get the URL like below.

http://honarsystems.com/wp-content/uploads/2021/11/image.jpg
Shopping Cart