Support

Account

Home Forums ACF PRO [Gallery – shortcode] Add data-attribute to link wrapping each image

Solved

[Gallery – shortcode] Add data-attribute to link wrapping each image

  • I’m using the Gallery custom field, and I’m displaying it in my template as a wordpress gallery, using the third method (gallery shortcode).

    I’d like to add the ‘data-featherlight=”image”‘ attribute to the links wrapping each image.

    Could you please explain how I might accomplish this?

    Thank you in advance for any help 🙂

  • FIXED

    I solved it, no worries. For anyone else wanting to implement this:

    /*
    Add featherlight data attribute to ACF gallery
    */
    function add_featherlight_gallery_attribute( $link ) {
    	
    	return str_replace( '>', ' data-featherlight="image">', $link );
    }
    add_filter( 'wp_get_attachment_link', 'add_featherlight_gallery_attribute', 10, 2 );
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘[Gallery – shortcode] Add data-attribute to link wrapping each image’ is closed to new replies.