Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17201

    Hi,

    I’m trying to use shortcodes within template files using the do_shortcode WP function, but they are not really working. Can you please tell me what I’m doing wrong? I’m trying with the toggle shortcode, but no luck:

    echo do_shortcode('[toggle_container keep_open="false"]');

    echo do_shortcode('[toggle title="Filter lessons"]Filter lessons content goes here.[/toggle]');

    echo do_shortcode('[/toggle_container]');

    I tried escaping the quotation marks, but that didn’t help.

    Thanks!

    #94547

    Hi,

    Try this instead

    echo do_shortcode(‘[toggle_container keep_open="false"][toggle title="Filter lessons"]Filter lessons content goes here.[/toggle][/toggle_container]‘);

    Regards,

    Ismael

    #94548

    That worked, thanks a lot!

    #94549

    And one more tip for anyone using this, if you want to add some PHP within the shortcode content, you need to concatenate like this:

    echo do_shortcode('[toggle_container keep_open="false"][toggle title="Filter lessons"]Filter lessons' . $extra_php_stuff . ' content goes here.[/toggle][/toggle_container]');

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Using shortcodes in template files’ is closed to new replies.