Site logo

[Support request] Add custom data attribute to all image links

Home Forums Support [Support request] Add custom data attribute to all image links

Home Forums Support Add custom data attribute to all image links

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2522565
    Trevor

    Hi, (sorry for the edit I had it all mixed up)

    Is there a way to us GP elements or similar to add a custom attribute to all image media file links? I have ACF to create a new attribute “data-sub-html” that can be filled in on the media library section where you can add title, alt text, etc.

    I have a lightbox plugin that will pull data-sub-html if it’s in the link attributes (with media link set to media file) and use it as the caption on lightbox popups.

    Right now the images look like this (simplified):
    <a href="img/img1.jpg"> <img src="img/thumb1.jpg" /> </a>

    How can I inject my attribute automatically so it becomes <a href="img/img1.jpg" data-sub-html="some html formatted text"> <img src="img/thumb1.jpg" /> </a>

    Apologies if this is outside the scope of GP, let me know and I’ll return to scouring google results.

    Thanks,

    #2522650
    Fernando
    Customer Support

    Hi Trevor,

    What we have for custom attributes is manual input as well. This is available in GB Pro: https://docs.generateblocks.com/article/custom-attributes/

    For that, you’ll need custom code. Unfortunately, this would be out of our scope of support. If it’s a Block, perhaps you can re-render the block with a data attribute through the WordPress render_block filter. Reference: https://developer.wordpress.org/reference/hooks/render_block/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.