How to check the presence of the attribute in WordPress shortcode

Many times in the development of sites i needed to check the presence of the attribute in WordPress shortcode before the content output. And specifically i like to use it to replace standard WordPress gallery. I change shortcode gallery as i need and add additional attributes to it. For example, you can add attribute type and depending it use various types and styles of gallery before content output.

Hovever, using different types of galleries leads to the use of a variety of styles and scripts. But all it increase pages download time. So for using only i need i usually check the presence of the attribute in WordPress shortcode and depending it include necessary styles and scripts.

I didn't find buld in function for checking presense of the attribute in WordPress shortcode i need. For it i use next function.

Function takes content, shortcode we're looking for and the attribute. If shortcode isn't present function return false, but if it is present function using regular expression check the presence of the attribute in WordPress shortcode. I like WordPress for it shortcodes. If attribute you're looking for is present function return true. You can shange regular expression as you need.


Leave a Reply

Your email address will not be published. Required fields are marked *