Opens in a new tab
16th May '26
/
0 comments

How to move data attributes from outer element to nested element in Bricks

Consider a scenario where a Container/Block in Bricks is made up of image on the left side and a heading with text blurb on the right with both image and heading linking to the same URL.

It is recommended to follow a Single Action Pattern in this case by setting aria-hidden: true and tabindex: -1 for the heading element's anchor tag for accessibility.

The problem though is that when these custom data attributes are added to the heading element, they apply to the heading itself:

when they should be applied to h4 > a, like this:

This Pro tutorial provides the code snippet for this.

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Modifying ACF Field Value Before It Is Output

Modifying ACF Field Value Before It Is Output

Consider the scenario where a Page has a "Page Fields" field group created with ACF Pro like this: Field name: scientific_coordinators (type Repeater)|__ Sub field…
Categories:
Pro
How to Inject a Different Type of Post in Bricks Query Loop

How to Inject a Different Type of Post in Bricks Query Loop

Updated on 26 Aug 2024 A user asks: Hello, I'd like to inject a CPT post card inside of a Bricks query loop of a different CPT…