• Hi All,

    I am creating a plugin which to allow me to upload an image into a widget. The upload part works well and stores the image in the media library. However, what I’m trying to do is actually display the uploaded image on the front end inside the widget. For the time being all I’m getting on the front end is the broken image icon. I am trying to use wp_get_attachment_url however one of the parameters is the image ID. I have no idea how to capture the ID. I’ve tried so many different things I am more confused than when I started. The code for this is:

    public function widget( $args, $instance )
        {
          ?>
    
           <img src=" <?php echo (wp_get_attachment_url($post->id)); ?> " /> <?php
        }

    But of course $post->id is wrong. If I hard code it, it works fine but that iis far from practical. Does anyone have any ideas?

  • The topic ‘Capturing the attached image URL’ is closed to new replies.