Skip to content
Advertisement

Extract shortcode parameters in content – WordPress

Think about a post content like below:

JavaScript

I have a shortcode that takes 3 or more parameters. I want to find out how many times the shortcode is used at the content and its parameters in an array like,

JavaScript

I need to do this in the_content filter, wp_head filter or something similar.

How can I do this ?

Thank you,

Advertisement

Answer

In wordpress get_shortcode_regex() function returns regular expression used to search for shortcodes inside posts.

JavaScript

Then preg_match the pattern with the post content

JavaScript

If it return true, then extracted shortcode details are saved in $matches variable.

Try

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement