WordPress.org

Support

Support » Plugins and Hacks » Squelch Tabs and Accordions Shortcodes » [Resolved] Best way to insert PHP into tabs?

[Resolved] Best way to insert PHP into tabs?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Matt Lowe

    @squelch

    Your question is a bit too involved to fully answer, but the answer is it depends. If you want to use tabs in a PHP template then you can do so using the do_shortcode() function. Basically you pass it text and it will find any shortcodes in that text and deal with it appropriately. So, for example, in your PHP template you could do:

    <?php
    // ...snip...
    
    echo do_shortcode(
        '[tabs]'
        .'[tab title="Tab one"]'
        .'Content for tab one'
        .'[/tab]'
        .'[/tabs]'
    );
    
    // ...snip...
    ?>

    Then, of course, you can replace ‘Content for tab one’ with whatever you want.

    Alternatively there are a number of plugins that allow you to embed PHP into your page or post’s content. See this plugin for example: http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/ Obviously there are potential security concerns around doing that, so use your common sense.

    Another option that I am very fond of is to simply create a new shortcode in a separate plugin or even in your theme’s functions.php file that does whatever it is you’re trying to achieve.

    Thank you for your quick response. I think the do_shortcode is is exactly what I was looking for. Thank you.

    This might be a separate topic but since I did this:

    echo do_shortcode(
                '[tabs title="" disabled="false" collapsible="false" active="0" event="click"]' .
                '[tab title="Ministry News"]' .
                    $userRegion
                . '[tab title="Ministry Volunteers"]Tab 1 content[/tab]' .
                '[tab title="Ministry Resources"]Tab 2 content[/tab]' .
                '[/tabs]'
            );

    The $userRegion variable is being displayed in the second tab with “Tab 1 content” and the first tab is blank. Is this my coding error or is something strange going on?

    Plugin Author Matt Lowe

    @squelch

    You’re missing a [/tab] after $userRegion:

    echo do_shortcode(
                '[tabs title="" disabled="false" collapsible="false" active="0" event="click"]' .
                '[tab title="Ministry News"]' .
                    $userRegion
                .'[/tab]'
                .'[tab title="Ministry Volunteers"]Tab 1 content[/tab]' .
                '[tab title="Ministry Resources"]Tab 2 content[/tab]' .
                '[/tabs]'
            );

    Works perfectly… thanks for helping a poor, dumb soul.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Best way to insert PHP into tabs?’ is closed to new replies.
Skip to toolbar