WordPress.org

Ready to get started?Download WordPress

Forums

PHP Variable in Shortcode (4 posts)

  1. dantemonaldo
    Member
    Posted 2 years ago #

    I wrote a simpe PHP script and have been trying to return the results in WordPress shortcodes, but I can't seem to get it to work. Here is what I have:

    function securetotal() {
        return $secure_total;
    }
    add_shortcode('secure', 'securetotal');

    $secure_total is the predefined variable that I need to be displayed. I can display simple text instead of the variable, but the variable is not transferring any results. Am I missing something? Any ideas?

    Help is much appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    you might need to set the variable to 'global'

    http://php.net/manual/en/language.variables.scope.php

  3. dantemonaldo
    Member
    Posted 2 years ago #

    Thanks a lot! I knew it was something small that I was missing.

  4. dantemonaldo
    Member
    Posted 2 years ago #

    What about having WordPress shortcodes wrapped inside a shortcode?

Topic Closed

This topic has been closed to new replies.

About this Topic