Title: PHP Variable in Shortcode
Last modified: August 20, 2016

---

# PHP Variable in Shortcode

 *  [dantemonaldo](https://wordpress.org/support/users/dantemonaldo/)
 * (@dantemonaldo)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/php-variable-in-shortcode/)
 * 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.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/php-variable-in-shortcode/#post-2592936)
 * you might need to set the variable to ‘global’
 * [http://php.net/manual/en/language.variables.scope.php](http://php.net/manual/en/language.variables.scope.php)
 *  Thread Starter [dantemonaldo](https://wordpress.org/support/users/dantemonaldo/)
 * (@dantemonaldo)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/php-variable-in-shortcode/#post-2592959)
 * Thanks a lot! I knew it was something small that I was missing.
 *  Thread Starter [dantemonaldo](https://wordpress.org/support/users/dantemonaldo/)
 * (@dantemonaldo)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/php-variable-in-shortcode/#post-2593156)
 * What about having WordPress shortcodes wrapped inside a shortcode?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP Variable in Shortcode’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [dantemonaldo](https://wordpress.org/support/users/dantemonaldo/)
 * Last activity: [13 years, 12 months ago](https://wordpress.org/support/topic/php-variable-in-shortcode/#post-2593156)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
