Tagged: accessibility, blog posts, hook
-
AuthorPosts
-
January 28, 2020 at 9:43 pm #1179198
Hi,
we need to remove the alt tag from the images in the “Blog Posts” component since the alt attribute is just a repeat of the text below the image – it leads to a duplication for screenreaders
is there any kind of hook/filter we can use to replace it with
alt=""
?thanks
January 29, 2020 at 8:27 pm #1179551Hey codemonkeynorth,
No, there is no such filter. Please have a look at this file
/enfold/config-templatebuilder/avia-shortcodes/blog/blog.phpIf you need further assistance please let us know.
Best regards,
VictoriaJanuary 29, 2020 at 10:03 pm #1179609it would appear to be part of
config-templatebuilder\avia-shortcodes\postslider.php
that the Blog Posts actually renders the item with, not blog.php.
$output .= $thumbnail ? "<a href='{$link}' data-rel='slide-".avia_post_slider::$slide."' class='slide-image' title=''>{$thumbnail}</a>" : '';
it’s the
$thumbnail
part we need to change in this instance to remove thealt
the correct method seems to be passing
false
to the alt parameter in the third argument
$thumbnail = get_the_post_thumbnail( $the_id, $image_size, array( 'alt' => false ));
we don’t really want to edit core theme files and I imagine this solution would normally be preferable, using a regex
add_filter( 'post_thumbnail_html', 'remove_thumbnail_alt', 10, 5 ); function remove_thumbnail_alt( $html, $post_id, $post_thumbnail_id, $size, $attr ) { $html = preg_replace( '/(alt)=\"(.*?)\"\s/', "", $html ); return $html; }
however I’m not sure we can run this function for only the blog posts entries
if we need to add a conditional to the core
postslider.php
file output to remove the alt if a title is available in the pod text, we need to make it a conditional on these render types
title, excerpt_read_more, title_read_moretherefore for now I’ve added a patch to
postslider.php
// patch: remove alt on image if there is a title output on the pod // $thumbnail = get_the_post_thumbnail( $the_id, $image_size ); $hasTitle = in_array($contents, ['title', 'excerpt', 'excerpt_read_more', 'title_read_more']); $thumbnail = get_the_post_thumbnail( $the_id, $image_size, ($hasTitle ? array('alt' => false) : null));
again we’d rather not edit core theme files, but I see no other solution really using filters/hooks
January 30, 2020 at 4:26 pm #1179964Hi codemonkeynorth,
Well, you did not specify the element you were using so I suggested that file. Well, you can copy this file to the child theme and do your changes there.
Best regards,
VictoriaJanuary 30, 2020 at 9:52 pm #1180085Hi.
It’s the “Blog Posts” component. This appears to use
postslider.php
, however when I copy it to my child theme with the same path it does not seem to pick up the new codeplease can you confirm that placing it at
my-child-theme\config-templatebuilder\avia-shortcodes\postslider.php
should allow me to change it there?I’m not sure why it didn’t work if that’s the case, unless it’s a caching issue
Thanks
JoeFebruary 4, 2020 at 4:22 am #1181135Hi,
Thank you for the update.
You have to register a new path for the shortcodes in the child theme directory. Please check the documentation below.
// https://kriesi.at/documentation/enfold/intro-to-layout-builder/#add-elements-to-alb
Create a folder in the child theme called shortcodes, then create a copy of the postslider templates inside it to override the original shortcode.
Best regards,
IsmaelFebruary 4, 2020 at 3:23 pm #1181305thanks that works for me!
February 4, 2020 at 8:05 pm #1181500Hi,
Did you need additional help or shall we close this topic?
Best regards,
Jordan ShannonFebruary 4, 2020 at 11:16 pm #1181576Our workaround will do for now thanks so the topic can be closed, but please be aware of the accessibility issues with the theme .
February 5, 2020 at 10:51 am #1181691Hi codemonkeynorth,
We’re glad to hear that :)
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘accessibility: blog posts component’ is closed to new replies.