admin管理员组文章数量:1316541
Hope everyone is having a good day. in WordPress Codex Post Format the image post format is defined as
image – A single image. The first tag in the post could be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
Now i need to know about what title attribute they are talking about in the above definition of image post format and how to retrieve that title through php as all the data is coming from the_content() function, anyone has any idea? i have researched online and there is literally no issue about this one.
Hope everyone is having a good day. in WordPress Codex Post Format the image post format is defined as
image – A single image. The first tag in the post could be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
Now i need to know about what title attribute they are talking about in the above definition of image post format and how to retrieve that title through php as all the data is coming from the_content() function, anyone has any idea? i have researched online and there is literally no issue about this one.
Share Improve this question asked Nov 12, 2020 at 13:37 Muhammad KashifMuhammad Kashif 304 bronze badges1 Answer
Reset to default 1So first off, I hope you're aware that the quote there is a guideline on how should a post of the image
format be displayed to the user, and the thing about the title attribute applies only to posts where the format is image
and that the post content is the image URL only, e.g. https://example/image.jpg
.
what title attribute they are talking about
It's the title
attribute of the <img>
tag, and the attribute value should be set to the post title.
how to retrieve that title through PHP
There are some functions you can choose from such as get_post_field()
, get_the_title()
and the_title_attribute()
.
So for example, your <img>
can be generated like so:
<img src="<?php echo esc_url( get_post_field( 'post_content' ) ); ?>"
title="<?php the_title_attribute(); ?>">
本文标签: theme developmenthow to retrieve the image title for image Post Format
版权声明:本文标题:theme development - how to retrieve the image title for image Post Format 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999941a2410806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论