Skip to content

Commit da41614

Browse files
authored
Merge pull request #172 from devgeniem/TMS-1017
TMS-1017: Add image alt-text to imported news
2 parents 5c25b78 + b0c5958 commit da41614

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

CHANGELOG.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
## [1.8.10] - 2024-03-18
1111

1212
- TMS-1015: Header accessibility fixes
13+
- TMS-1017: Add image alt-text to imported news
1314

1415
## [1.8.9] - 2024-02-01
1516

lib/Traits/EnrichPost.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public static function enrich_post(
3333
int $excerpt_length = 160
3434
) {
3535
if ( $use_images ) {
36-
$api_image = get_field( 'image_url', $post->ID );
36+
$api_image = get_field( 'image_url', $post->ID );
37+
$api_image_alt = get_field( 'image_alt', $post->ID );
3738

3839
if ( ! empty( $api_image ) ) {
3940
$post->api_image_url = $api_image;
41+
$post->api_image_alt = $api_image_alt;
4042
}
4143
else {
4244
$post->featured_image = has_post_thumbnail( $post->ID )

models/single.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function content() {
8686
: $single->image;
8787

8888
$single->api_image_url = empty( $single->image ) ? get_field( 'image_url' ) : false;
89+
$single->api_image_alt = empty( $single->image ) ? get_field( 'image_alt' ) : false;
8990
$single->has_image = ! empty( $single->image ) || ! empty( $single->api_image_url );
9091

9192
if ( 'blog-article' === $single->post_type ) {
@@ -136,6 +137,7 @@ public function related() : ?array {
136137
: [];
137138

138139
$item->api_image_url = get_field( 'image_url', $item->ID );
140+
$item->api_image_alt = get_field( 'image_alt', $item->ID );
139141
$has_image = $item->image_id !== 0 || ! empty( $item->api_image_url );
140142

141143
if ( ! $has_image ) {

partials/single.dust

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737

3838
{?content.api_image_url}
3939
<div class="entry__figure pt-2">
40-
<img src="{content.api_image_url|url}" loading="lazy"/>
40+
<img src="{content.api_image_url|url}"
41+
{?content.api_image_alt}alt="{content.api_image_alt|attr}"{/content.api_image_alt}
42+
loading="lazy" />
4143
</div>
4244

4345
{>"views/single/single-meta" spacing_class="pt-5 pt-4-desktop pb-5 p-5-tablet" /}

0 commit comments

Comments
 (0)