Viewing 2 replies - 1 through 2 (of 2 total)
  • I’d love to be able to do this too.

    Couldn’t you just use the do_shortcode() function? It’s pretty simple to use usually.

    How it’s usually used in it’s simplest form:
    <?php echo do_shortcode( '[shortcode]' ) ?>

    The tooltip shortcode is a little different because we also have a closing tag:
    [/tooltip]

    So we write the full shortcode this way:
    [tooltip tip="Popup tooltip text."]some text here[/tooltip]

    Ok, fine. So to do this in PHP, I would first assign a variable for the “some text here” portion so that we may neatly call this in the do_shortcode() function:
    $tooltip_text = "some text here.";

    I will then simply display the results of the shortcode using the echo construct:
    echo do_shortcode( '[tooltip tip="This is the tooltip popup text."]' . $tooltip_text . '[/tooltip]' );

    As you can see, we’re echoing (or displaying) the shortcode exactly as we would normally, only this time using a variable for the title text.

    The full PHP code would look something like this. I put mine inside <div> tags:

    <div class="tooltipShortcode">
    <?php
    $tooltip_text = "Title text of the tooltip.";
    echo do_shortcode( '[tooltip tip="This is the tooltip popup text."]' . $tooltip_text . '[/tooltip]' );
    ?>
    </div>

    For more information on using shortcodes in PHP, check this out:
    http://codex.wordpress.org/Function_Reference/do_shortcode

    Hope this helps. Have fun!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can this be added in a PHP template?’ is closed to new replies.