-
usethebitcoin
Hi there,
I wanted to ask if it is possible to add some aria-label for a query result? like get the blog article title post and use that as aria-label. In our homepage we are showing categories by using query, then I want to add aria-label for each query showing by getting the title of the article as aria-label.
Thank you.
-
Hi there,
In our homepage we are showing categories by using query, then I want to add aria-label for each query showing by getting the title of the article as aria-label.
When you say query, do you mean GB’s query loop block?
Can I see the categories on your homepage?
-
usethebitcoin
Hi Ying,
Yes GB query.
https://i.postimg.cc/g2vFnHcG/Screenshot-18.jpg
This is how I called the gategories in our homepage.
https://i.postimg.cc/Px5BVGWq/Screenshot-20.jpg -
then I want to add aria-label for each query showing by getting the title of the article as aria-label.
Do you mean add an
aria-label
to each post in the query loop? Or to the query loop? -
usethebitcoin
To add aria-label to each post in the query loop. Like getting all the titles and placing them as an aria-label on each article.
-
Why would you want to do that? The title has descriptive text, an element like that does not require an
aria-label
, and if the aria-label is the same as the title, the text will be doubled, I don’t think it’s good for SEO as well.But if you really want to do that, try this method:
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', 'aria-label="'. $title .'" class' ,$block_content); } return $block_content; }, 10, 2 );
2. Add class
my-query
to the post template container of the query loop block. -
usethebitcoin
Thank you Ying,
I am solving some SEO issues, but this was already solved, but maybe in the future I will be needing this.
Thank you very much.
-
No Problem 🙂
- You must be logged in to reply to this topic.