Within a span, the shortcode output works:

<span>[sola_testimonials_count type="all"]</span>

Result:
<span>5,205</span>

But as an attribute value, it doesn’t get parsed:

<span data-value="[sola_testimonials_count type=\'all\']"></span>

Result:
<span data-value="[sola_testimonials_count type=\'all\']"></span>

This is a third-party plug-in, but I obviously have the code and can manipulate it. Is there a way I can get the shortcode to parse as an HTML attribute value? I’m not a WordPress developer so forgive me if this is an obvious answer.

Many thanks!

3 Answers
3

I am not good at Regex but do_shortcode will basically will not parse any shortcode in the attributes, this might help you out:

add_filter('the_content', function($c){
    $pattern = '/<span\s*(.*?)data-value=["\']?\[(.*?)\]["\']?\s*(.*?)>\s*(.*?)\s*<\/span>/si';
    $c = preg_replace_callback($pattern, function($c){
        return isset( $c[2] ) ? str_replace(
            $c[2],
            do_shortcode("[{$c[2]}]"),
            $c[0]
        ) : array_pop($c);
    }, $c);
    return $c;
});

Leave a Reply

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