Search code examples
imagewordpresspostaviary

How to pass the HTML ID and URL of image in a WP post?


I want to incorporate the Aviary editor into WordPress posts so that people can click an edit button for the image in the post, edit it and save it. Aviary has provided code for the last two, but I do not know how to pass the HTML ID and URL of the image in the post in an input tag for the edit button. I know this is basic, but I am not a programmer, so I would sure appreciate your patience and feedback. Thanks.

Here is the input static code Aviary provides:

<!-- Add an edit button, passing the HTML id of the image and the public URL of the image --><p>
<input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' 
onclick="return launchEditor('imageid', 'url');" /></p>

I need to know how to pass the ID and URL for the last line of the code. Thanks so much for any feedback you can offer.


Solution

  • the imageid is the div id to use by aviary, you just need tu create

    <div id="imageid"></div>
    

    An to get the image url you can to like this

    <?php
      $image = wp_get_attachment_image_src($post->ID);
      $url = $image[0];
    ?>
    
    <input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('imageid', '<?php echo $url; ?>');" /></p>
    

    I assume that you will place it in attachment page