Support » Plugin: WooCommerce Coupon Shortcodes » How to add short code to theme php

  • Resolved Szyam

    (@szyam)


    Hello, I typically add shortcodes in my theme with the function echo do_shortcode.
    Since this has a conditional ‘wrapping’ format I’m curious how I would do it.

    Like this?

    <?php echo do_shortcode(‘[coupon_is_active code=”easterbunny”]’) : ?>
    <p>this is some html to show if coupon is active</p>
    <?php echo do_shortcode(‘[/coupon_is_active]’) : ?>

Viewing 1 replies (of 1 total)
  • Hi Szyam,

    I think that you would have to include the complete shortcode within the call:

    echo do_shortcode(
        '[coupon_is_active code="easterbunny"]' .
        '<p>this is some html to show if coupon is active</p>' .
        '[/coupon_is_active]'
    );

    Otherwise WordPress would not handle it correctly.

    Cheers

    • This reply was modified 11 months, 1 week ago by Kento.
Viewing 1 replies (of 1 total)
  • The topic ‘How to add short code to theme php’ is closed to new replies.