Is there a way to have a shortcode aware of it's parent shortcode?

I’m wanting to build a shortcode for my theme that allows me to show a gallery of images/videos. I’m thinking the markup might be something like:

    {{<figure src="..." ...>}}
    {{<figure src="..." ...>}}

What I’m hoping I can do is have the figure shortcode be aware that it’s inside a gallery and therefore behave differently to normal. I’m already using a custom figure shortcode to provide responsive images but I don’t know if I can discover the context that it’s called in.


This will take you directly to the section of the page that contains an example of something very similar to what you’re looking for…

Ha, I stared at that part of the page for an age thinking “this doesn’t do what it needs to”. On rereading, it does, of course. The key is the .Parent check you can do.