Making WordPress.org

Ticket #5985: 5985.diff.1

File 5985.diff.1, 1.3 KB (added by alexstine, 2 years ago)

Adds alt attribute based off caption with fallback text if one does not exist.

Line 
1Index: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-photos/template-parts/photo-single.php
2===================================================================
3--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-photos/template-parts/photo-single.php    (revision 11597)
4+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-photos/template-parts/photo-single.php    (working copy)
5@@ -55,13 +55,16 @@
6        </header><!-- .entry-header -->
7 
8        <div class="entry-content">
9+               <?php
10+               $caption = get_the_content();
11+               $image_alt = ( $caption ? wp_strip_all_tags( $caption, true ) : __( 'No image caption provided', 'wporg-photos' ) );
12+               ?>
13                <figure>
14                        <a href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>">
15-                               <img class="grid-photo" src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'medium'); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_post_thumbnail_id() ) ); ?>">
16+                               <img class="grid-photo" src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'medium'); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_post_thumbnail_id() ) ); ?>" alt="<?php echo esc_attr( $image_alt ); ?>">
17                        </a>
18 
19                        <?php
20-                       $caption = get_the_content();
21                        if ( $caption ) {
22                        ?>
23