If you take a look at native galleries they already have IDs with counter implemented:
$instance++;
...
$selector = "gallery-{$instance}";
...
$gallery_div = "<div id='$selector'class="gallery...
So first gallery within a post will have <div id="gallery-1"... and so on. This is used by core itself to target different styles at each instance.
If you need to do something more custom you can use gallery_style filter, which gets passed those styles and opening div markup, to similarly keep track of instances and inject your custom classes as necessary.
Related Posts:
- Check if post/page has gallery?
- how to have the gallery shortcode output one single UL list instead of several DL?
- Automatically add this attribute to the gallery shortcode
- How do i link gallery thumbnails to different url’s using the wp native gallery?
- WordPress gallery ‘post_gallery’ filter doesn’t work with feeds?
- conditional shortcode not working
- Remove width and height attributes from [gallery] output
- Gallery shortcode menu order fix no longer working on WordPress 4.0
- conditional shortcode not working
- Some doubts about gallery shortcode in WordPress
- Should I cache default WordPress gallery shortcode output?
- Numbering Image List in Gallery
- Rewriting WordPress Gallery Shortcode with Bootstrap Carousel
- change wordpress gallery shortcode to slider
- Remove hyperlink on gallery shortcode
- Add custom setting that uses radio button to WP Gallery
- WordPress Gallery shortcode: Display one category ID only
- How to get gallery id inserted to a post?
- Check if post has gallery images/media
- How to Modify WordPress Default Image Gallery Shortcode
- Change WordPress Shortcode added in to post
- Gallery shortcode – change link file image size? (not using default fullsize image)
- add action only if gallery shortcode attribute is equal to?
- Unable to the get the gallery inserted between shortcodes
- Adding shortcode field to edit gallery / Gallery Settings
- How to change the output of gallery shortcode
- Replacement for gallery_shortcode function not taking all attributes
- How to Retrieve data of Gallery Shortcode and display it above a post
- How to copy [gallery] shortcode between posts using polylang [closed]
- Which file renders the “Edit Gallery” Settings page?
- How to display NextGEN gallery in templates?
- Use full size images in a specific gallery
- How to Enable embedding WordPress default gallery in comments?
- How to add new images to existing shortcode configuration?
- Gallery shortcode is empty but magically creates a gallery
- Can we add a single caption to the gallery shortcode?
- Replace custom gallery shortcode with default gallery shortcode
- WordPress Gallery with ID’s Shortcode not Working
- Remove width and height attributes from [gallery] output
- Changing layout of defaul gallery output to masonry
- What makes a placeholder resizable in Tinymce?
- how to show last 5 images from the one post gallery
- Gallery Shortcode: using size=”full” doesn’t call the actual thumbnail image size
- Shortcode always displaying at the top of the page
- short code output too early
- Create custom [sourcecode] shortcode, the right way?
- TED talks shortcode not working
- Set wmode attribute to transparent for the embed shortcode to make drop-down menu hover over YouTube embed in Internet Explorer
- how do you get the author’s username?
- do_shortcode inside AJAX callback
- How to create a shortcode to display a category description?
- shortcode not working and the relation to the_content()
- Correct way to pass information between seperate shortcode functions
- Extending Shortcode attributes
- If numberposts = -1 offset won’t work
- Shortcode are not working in Option tree textarea
- Font Awesome Icons Won’t Work
- detect when shortcode ran for the last time
- How can a shortcode can take the place of the featured image in a post?
- Shortcode for Twitter Bootstrap Collapse
- Is there any inherent difference between add_filter() and add_shortcode() for modifying [caption]?
- Different uniqid when calld in wp_localize_script and shortcode
- How do I debug a short code?
- Shortcode pagination not advancing
- How to type shortcode-like text in WordPress TinyMCE visual editor?
- Does registering multiple shortcodes impact performance?
- How To Conditionally Include A Short Code Depending On The HTTP_REFERER [closed]
- Shortcode for order number [closed]
- Buddypress shortcode for tabs [closed]
- PHP Running On CMS Side of WordPress
- Basic do shortcodes question
- What is this format called (nested shortcodes)?
- Problem with height in video shortcode
- When are Shortcode Attributes Available in Template
- Shortcode inside text widget do not call enqueue style
- How to create a dropdown of shortcodes in edit mode for posts
- Checking post content for a shortcode, but content is being returned as empty
- do_shortcode() won’t return PHP Array
- Show shortcode only in posts
- get_queried_object_id / short code returning blank
- shortcode to display specific recent posts
- How to test If a post has a particular term
- Multiple values for one variable
- shortcode is not rendered
- Impossible to display modification in shortcode code?
- Use Shortcode on Custom Page
- WordPress Database Error using $wpdb->get_results()
- Ajax callback and shortcode functionality
- WordPress plugin shortcodes not outputting anything
- Featured image with link to post shortcode, image displaying above the post
- How to stop unwanted splits in excerpts when using shortcodes for sliders or players
- Inserting shortcode is blanking excerpt – any ideas?
- Escaping a shortcode so it displays as-is [duplicate]
- If do_shortcode is blank, return some message
- Previous/Next with the same category
- I’ve broken the short code for Contact Form 7!
- echo a shortcode in a shortcode code?
- Applying if (get_post_meta) to new shortcode
- wordpress how to sort posts on custom data with plug-in “Search & Filter”
- How to reuse php templates as shortcodes?