-
kiant123
in my pagespeed insights i’m getting the issue of links do not have a discernible name. One instance seems to be coming from my post template in my related posts where I have put the whole container as a link. I think I need to fill out the aria label section but i am not sure what to write in this box.
Also, I am getting the same issue coming from my social icons in my footer. I guess I have to do something similar again but not sure what values to put for them.
Thanks in advance!
-
Hi there,
Try this method to add aria-label to the container link.
1. Add this PHP code:
add_filter( 'render_block_generateblocks/container', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'my-query' ) !== false ) { $post_id = get_the_ID(); $title = get_the_title( $post_id ); $block_content = str_replace('class="gb-container-link"', 'aria-label="'. $title .'" class="gb-container-link"' ,$block_content); } return $block_content; }, 10, 2 );
2. Add a class to the post template block in the query loop, eg.
my-query
, note if you want to use other classes, make sure you change it in the PHP code as well 🙂Let me know if this helps!
-
kiant123
Hi,
Thanks for that. Am I not able to just put a value into the box shown in the image? Or will this way not work?
-
For the image? I thought you wanted to add
aria-label
to the container link, no? -
kiant123
No for the post template/container. In the screenshot I sent the aria link option is in the box for the container link. I assumed you could just put a value in here and it would apply to the container?
-
That option is not dynamic, if you fill that option, every
aria-label
will be the same.And isn’t the container link the only link in the post template?
- You must be logged in to reply to this topic.