plugin development - How to get post image root URL?

By using below code, I got Image url like "http:localhost..." but I need root path of that image from "

By using below code, I got Image url like "http://localhost..." but I need root path of that image from "var/www/html/.... "

 $FeaturedImage = wp_get_attachment_image_src( get_post_thumbnail_id(
 $post->ID ), 'homepage-column1' );

Is there any way to get root path of the post thumbnail?

By using below code, I got Image url like "http://localhost..." but I need root path of that image from "var/www/html/.... "

 $FeaturedImage = wp_get_attachment_image_src( get_post_thumbnail_id(
 $post->ID ), 'homepage-column1' );

Is there any way to get root path of the post thumbnail?

Share Improve this question asked Jul 6, 2019 at 6:07 Prashant PatilPrashant Patil 1136 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The get_attached_file() function returns the path to a file based on the attachment ID:

$FeaturedImage = get_attached_file( get_post_thumbnail_id() );

Getting the path to a specific size is more complicated. WordPress stores the filename for resized versions of the images in as attachment metadata, that can be retrieved with wp_get_attachment_metadata(). Once you have the filename of the resized version, you just need to replace the original filename in the path with the resized version's filename:

$image_id   = get_post_thumbnail_id();
$image_meta = wp_get_attachment_metadata( $image_id );
$image_path = get_attached_file( $image_id );

if ( isset( $image_meta['sizes']['homepage-column1']['file'] ) ) {
    $image_path = str_replace( $image_meta['file'], $image_meta['sizes']['homepage-column1']['file'], $image_path );
}

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

相关推荐

  • plugin development - How to get post image root URL?

    By using below code, I got Image url like "http:localhost..." but I need root path of that image from "

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信