I am referring to this codex, https://codex.wordpress.org/Function_Reference/media_handle_upload

There I can attach the uploaded image to the post as attachments by this :

$attachment_id = media_handle_upload( 'my_image_upload', $_POST['post_id'] );

But, I want to just get the url of the uploaded image, without adding the image as the post attachments.

How can I get that uploaded image url ?

1 Answer 1


You can get it with:


More info in the codex

In your example:

$attachment_id = media_handle_upload( 'my_image_upload', $_POST['post_id'] );
$attachment_url = wp_get_attachment_url($attachment_id);
echo $attachment_url; 
  • Hi, I don't want to add it as attachments to the post. Commented Aug 21, 2015 at 7:00
  • I edited my answer. Hope this helps.
    – amespower
    Commented Aug 21, 2015 at 15:15

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.