最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post meta - How to Display Image Caption but Not Alt Text

programmeradmin1浏览0评论

I'm trying to display images with their caption, but when I do it displays both the caption and that alt text. I've tried to use unset( $fields['image_alt'] ); to hide the alt text, but it does nothing. Here's my code:

                    <?php if (the_post_thumbnail_caption()) { 
                         the_post_thumbnail_caption();                          
                        } 

                        function remove_alt( $fields ) {
                            unset( $fields['image_alt'] );
                            return $fields;
                        }
                        add_filter( 'attachment_fields_to_edit', 'remove_alt', 999, 1 );
                    ?>

It first gets the caption, if there is one, and then the function is supposed to remove the alt text and keep the caption, but it's not working. Any suggestions for how to get this to work? Thanks so much for the help :)

I'm trying to display images with their caption, but when I do it displays both the caption and that alt text. I've tried to use unset( $fields['image_alt'] ); to hide the alt text, but it does nothing. Here's my code:

                    <?php if (the_post_thumbnail_caption()) { 
                         the_post_thumbnail_caption();                          
                        } 

                        function remove_alt( $fields ) {
                            unset( $fields['image_alt'] );
                            return $fields;
                        }
                        add_filter( 'attachment_fields_to_edit', 'remove_alt', 999, 1 );
                    ?>

It first gets the caption, if there is one, and then the function is supposed to remove the alt text and keep the caption, but it's not working. Any suggestions for how to get this to work? Thanks so much for the help :)

Share Improve this question asked May 1, 2020 at 20:44 frincifrinci 1
Add a comment  | 

1 Answer 1

Reset to default 0
echo wp_get_attachment_caption(get_post_thumbnail_id());
发布评论

评论列表(0)

  1. 暂无评论