I have this shortcode
[learn_more caption="something here:"]
[/learn_more]
I want to extract the caption value and remove other stuff. “something here:”
This is the code that I have, but it print the shortcode as it is.
$exclude_codes = 'learn_more';
$wp_content = preg_replace("~(?:[/?)(?!(?:$exclude_codes))[^/]]+/?]~s", '', $wp_content);
Thanks
I read your question differently than @eric-holmes. It sounds to me like your shortcode needs to function normally under most circumstances but that you are extracting information in special circumstances.
Shortcode regex is tricky. Let WordPress do it for you.
Your attributes for any shortcodes present in
$wp_content
should now be in$matches[3]
. You want to do something like…You will still need to clean the string a little bit as you will have a “caption=” in there but you are far ahead of where you started, and you could do that at the same time you set
$captions
withstr_replace
orpreg_replace
depending on how complicated you need the match.Getting attribute value from shortcode
Thanks every one for help, actually I solved the problem without using regex at all. I use wp-mpdf plugin with wp-event-manager, when I try to output the event page to PDF some content didn’t show like title, and some content, .. and that’s what cause the problem, but after some customization I was able to get the content from different places and the problem is solved.
code from wp-mdf.php in mpdf_output function