You’ll want to use wp_get_attachment_image_url()
or wp_get_attachment_image()
. You just pass them the ID of the image in the database and the size you want.
wp_get_attachment_image_url()
gives you the URL of the image:
echo wp_get_attachment_image_url( $attachment_id, 'large' );
// http://example.com/wp-content/uploads/2017/01/image-1024x1024.jpg
While wp_get_attachment_image()
gives you a full image tag:
echo wp_get_attachment_image( $attachment_id, 'large', false, [ 'class' => 'my-image' ] );
// <img src="http://example.com/wp-content/uploads/2017/01/image-1024x1024.jpg" class="my-image" etc...
If you do want it from your theme folder, then a better method these days is get_theme_file_uri()
, because it supports being filtered or being replaced by child themes:
echo get_theme_file_uri( '/img/bridge_ico.png' );