Function to get URL of original uploaded image – full size

I am currently using the following code to get the URL of the featured image of a wordpress post:

URL="<?php if (function_exists('wp_get_attachment_thumb_url')) {echo wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID), 'big-size'); }?>"

But the code only returns the smaller (150x150px) thumbnail. This is what I get:

http://sitename.com/wp-content/uploads/imagename-150x150.png

My question is, how do I get it to return the URL for the original image (full sized image) which would be:

http://sitename.com/wp-content/uploads/imagename.png

Many thanks for your time and help.

3

There are four valid sizes built in to the WordPress core.

the_post_thumbnail('thumbnail');    // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');       // Medium resolution (default 300px x 300px max)
the_post_thumbnail('medium_large'); // Medium Large resolution (default 768px x 0(means automatic height by ratio) max) since WP version 4.4
the_post_thumbnail('large');        // Large resolution (default 640px x 640px max)
the_post_thumbnail('full');         // Original image resolution (unmodified)

The last is one you’re looking for.

The following returns the URL.

<?php
  $src = wp_get_attachment_image_src( $attachment_id, $size, $icon );
  echo $src[0];

The whole code can look like that:

<?php
  $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false );
  echo $src[0]; // the url of featured image

More information can be found here.

Leave a Comment