Add a Data Attribute to a WordPress Gallery via jQuery

You can add a data attribute and value to a WordPress gallery via jQuery

jQuery(document).ready(function($){

$('#gallery-1 a').each(function() {
 $(this).attr('data-gall', 'gallery-mine' );
 });

});

So above we are targetting the a link tags that are the descendants of the gallery with an id of #gallery-1

They are then given a data attribute of data-gall and a value of gallery-mine.

Author: wpbeaches

Share a little biographical information to fill out your profile. This may be shown publicly. Share a little biographical information to fill out your profile. This may be shown publicly. Share a little biographical information to fill out your profile. This may be shown publicly.