Site logo

Archived topic

Possible to add class and other data-elements to tag

5 replies · Started by Eugene on April 7, 2022

Viewing posts 1–6 of 6

Hi there

2 part question:

1) Is it possible to add a class to an <a> tag directly in the editor? I could only get the class on the parent <p> element: https://prnt.sc/1DrS-jWCxmZd

2) More advanced: Is there a way to add data-attributes to <a> tags? Example:
<a class="villa-list-item enquire-modal-listing" data-villa="Villa Boma" data-action="Enquire Now" data-location="Listing" target="_self" href="#enquire-now-popup" data-lity=""></a>

Hi there,

the block editor doesn't allow for that.
You would need to switch to the Code Editor ( 3 dot menu in top bar ) to edit the HTML.

WP may not like that - and if thats the case then you would need to use a HTML block.

Thanks!

You're welcome

Hi I have to do same things. But I want to add by function.php. When i try with this edit as html , it fails and asked to "attempt recovery and effect was gone. I have to use Generatepress blocks and creating a button with custom data id and type in it. Can you please help in this regards ?

Hi there,

are you using GenerateBlocks Pro ?
As it provides Data Attributes in the GB Blocks Advanced panel.

This archived topic is closed to new replies.