title: Wordpress: Custom shortcode to render image with meta data
body: <p>My problem: <strong>How to pull the media data out of the database in PHP</strong>?</p>
  <p>I'd like to write a shortcode that renders an image with the alt-text and caption taken automatically from the media database. Usage-example:</p>
  <pre><code>[img 126 300]  // [img media-id width]
  </code></pre>
  <p>Intended Output:</p>
  <blockquote>
  <p><a href="https://i.stack.imgur.com/rQbZd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rQbZd.png" alt="Demo image" /></a></p>
  <p><em>Caption from Database</em></p>
  </blockquote>