Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
What have you tried so far? –  kaiser Feb 17 at 23:22

1 Answer 1

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 ); ?>" />
share|improve this answer
1  
Please add an explanation to your answer: why could that solve the problem? –  toscho Apr 25 at 20:03
    
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? –  unifiedac Apr 25 at 20:15
    
Next time you should edit your answer and add your extra info to that –  Pieter Goosen Apr 26 at 5:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.