On wp-admin/post.php?post=447&action=edit for example I have a link and an input.

The link appears as follows:

<a href="#" class="button insert-media add_media" data-editor="tj_image_url" >gallery</a>

When I click the link the media library opens, and i’d like the URL of the inserted image to populate an input field, eg.

<input type="text" name="tj_image_url" id="tj_image_url" value="VALUEHERE" size="30" />

How can I do this?

2 Answers
2

I am assuming you have a way to generate the attachment ID when inserting the image. You can then use the attachment ID to populate the input value. Are you not talking about an on-page input field?

Try something like this:

<?php 
//First get the attachment ID
$attachment_id = 8;
?>

<input type="text" name="tj_image_url" id="tj_image_url" value="<?php echo wp_get_attachment_url( $attachment_id ); ?>" />

Leave a Reply

Your email address will not be published. Required fields are marked *