Sridhar Katakam
Sridhar Katakam

Reputation: 1226

Modifying HTML of a specific [products] shortcode instance

The HTML output of [products] shortcode can be changed using hooks as outlined in /wp-content/plugins/woocommerce/templates/content-product.php.

Is it possible to have the hook code only affect a specific shortcode output?

Upvotes: 1

Views: 316

Answers (1)

Gijo Varghese
Gijo Varghese

Reputation: 11780

You can use the do_shortcode_tag filter.

The do_shortcode_tag (introduced in WordPress 4.7) filter allows you to modify the output of a shortcode before it gets mixed in with a post’s content.

Example:

function modify_shortcode_output( $output, $tag ) {
    if (  $tag === 'gallery'  ) {
        return $output."modified!";
    }
    return $output;
}
add_filter('do_shortcode_tag', 'modify_shortcode_output', 10, 2);

Upvotes: 1

Related Questions