title: WordPress custom metabox not saving data or display
body: <p>After two days of research and questions without answer, today someone has suggested a way to add a custom metabox field to the Wordpress images. My scope is to add a URL when the images are uploaded or modified and for now I'm only able to display the input field where user can add the URL, but the input will not be saved and I'm unable to get it back on the front-end.</p>
  
  <p>I want to use this custom metabox function with the <code>get_post_gallery()</code> that will output the URLs of the images I've added inside a gallery, but I don't know how to combine this, and I need to fix the saving of the inserted URL. Can anyone help me or guide through the implementation?</p>
  
  <pre><code>&lt;?php
   function add_image_link()
   {
     add_meta_box(
       'image_link_box',
       'Link image to url',
       'image_link_field',
       'attachment'
     ); 
   }
   add_action( 'add_meta_boxes_attachment', 'add_image_link' );
  
   function image_link_field( $post )
   {
     ?&gt;
     &lt;label for="image-link"&gt;Link URL&lt;/label&gt;
     &lt;input type="text" name="image_link" id="image-link" class="postbox"&gt;
     &lt;?php
   }
  
   function save_image_link( $post_id )
   {
     if( array_key_exists( 'image_link', $_POST ) ){
       update_post_meta(
         $post_id,
         'image_link_url',
         $_POST['image_link']
       );
     }
  
   }
   add_action( 'save_post_attachment', 'save_image_link' );
  ?&gt;
  </code></pre>