admin管理员组文章数量:1516870
How to display some information of featured image in post.
I need to display:
1.
a. Image file size (in kb or MB)
b. Image type (.jpg,.gif...),
c. Bare image name, with and/or without image extension (some-image-file-name.jpg).
Also, if it possible it would be nice to show this too:
d. orientation of image (landscape, portrait)
Maybe it will be helpful if I say that I do not have any image in post content, only as featured image.
It would be great to have separate functions to display that info of "medium" and image in "full" size, or at least of "full" size.
Could you please give me some functions which I can put in my theme files to display that info of featured image?
2.
I managed to show image title, caption and description of featured post image with:
echo get_post(get_post_thumbnail_id())->post_title;
echo get_post(get_post_thumbnail_id())->post_excerpt;
echo get_post(get_post_thumbnail_id())->post_content;
But, how to show image alt ("Alt Text") of featured image?
How to display some information of featured image in post.
I need to display:
1.
a. Image file size (in kb or MB)
b. Image type (.jpg,.gif...),
c. Bare image name, with and/or without image extension (some-image-file-name.jpg).
Also, if it possible it would be nice to show this too:
d. orientation of image (landscape, portrait)
Maybe it will be helpful if I say that I do not have any image in post content, only as featured image.
It would be great to have separate functions to display that info of "medium" and image in "full" size, or at least of "full" size.
Could you please give me some functions which I can put in my theme files to display that info of featured image?
2.
I managed to show image title, caption and description of featured post image with:
echo get_post(get_post_thumbnail_id())->post_title;
echo get_post(get_post_thumbnail_id())->post_excerpt;
echo get_post(get_post_thumbnail_id())->post_content;
But, how to show image alt ("Alt Text") of featured image?
Share Improve this question asked Jun 28, 2014 at 13:19 Advanced SEOAdvanced SEO 6892 gold badges16 silver badges41 bronze badges2 Answers
Reset to default 4Question 1: use wp_get_attachment_metadata in the Codex
or the search function on this forum!
Question 2: Put this in one of your functions. It will echo the Alt text for the image.
$img_id = get_post_thumbnail_id( get_the_ID() ); //Note: you may need other methods to get id
$alt_text = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
if (!empty ($alt_text) ) {
echo 'The Alt text: ' . $alt_text;
} else {
echo "No cigar!";
}
For 1C, you can use pathinfo() to retrieve the file information:
$file = pathinfo( 'http://your-website/wp-content/uploads/2019/03/your-photo.jpg' );
echo $file['dirname']; // http://wpmasterclass.localhost/wp-content/uploads/2019/03
echo $file['basename']; // your-photo.jpg
echo $file['extension']; // jpg
echo $file['filename']; // your-photo
If you only need filename and extension, a straightforward alternative is by using basename():
$file = basename('http://your-website/wp-content/uploads/2019/03/your-photo.jpg');
echo $file; // your-photo.jpg
本文标签:
版权声明:本文标题:post thumbnails - Display featured image file size, extension, filename, type, orientation? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1748623865a2858165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论