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 (

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:

.png

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

.png

Many thanks for your time and help.

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/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/wp-content/uploads/imagename.png

Many thanks for your time and help.

Share Improve this question asked Nov 3, 2014 at 17:27 theshorttreetheshorttree 1971 gold badge2 silver badges10 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 41

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.

For those who are coming here post October 2019

WordPress has introduced a "Big Image Threshold" since version 5.3 (Link)

In short all images above 2560px will be downscaled on upload. Calling the image format "full" will no longer always return the original untouched image but might return that 2560px version and will have '-scaled' in the url and path.

You can still get the url and path of the originally uploaded images with the following functions: wp_get_original_image_path() or wp_get_original_image_url(). Although the documentation suggests a new size "original_image" was added, wp_get_attachment_image, wp_get_attachment_image_src or similar functions still return the scaled down version. So as far as I can tell no way to get the original file dimentions etc.

A bit late to the party,

but

get_the_post_thumbnail_url(null,'full'); does exactly the job, where full can be replaced by thumbnail, medium, medium_large or large.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744509490a4577905.html

相关推荐

  • 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 (

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信