WordPress.org

Forums

Squelch Tabs and Accordions Shortcodes
[resolved] Best way to insert PHP into tabs? (6 posts)

  1. am71722
    Member
    Posted 2 years ago #

    I'm really new to WordPress so I was wondering how to get PHP into the tabs. I'm currently making a template for a couple of pages so if it can be done programmaticly that's great too.

    http://wordpress.org/extend/plugins/squelch-tabs-and-accordions-shortcodes/

  2. Matt Lowe
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. am71722
    Member
    Posted 2 years ago #

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

  4. am71722
    Member
    Posted 2 years ago #

    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?

  5. Matt Lowe
    Member
    Plugin Author

    Posted 2 years ago #

    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]'
            );
  6. am71722
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Squelch Tabs and Accordions Shortcodes
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags