Title: Creating a Variable for a Shortcode
Last modified: February 15, 2022

---

# Creating a Variable for a Shortcode

 *  Resolved [hemjesti](https://wordpress.org/support/users/hemjesti/)
 * (@hemjesti)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/creating-a-variable-for-a-shortcode/)
 * hey guys, I am NOT a coder by any means, but I’m trying to make this happen.
 * I have a number tied to locations we service and it changes and instead of changing
   it on 300 pages, I’d like to change it in one spot, and replace those 300 locations
   with a variable or shortcode.
 * I have found this code, but, I’m not sure how I should use it. I’d like to be
   able to use something like [varFSL] as my shortcode, and I think this code will
   let me do that, but I don’t know what the $i is all about, I thought that was
   an increment?
 *     ```
       function my_shortcode_function() { 
       $i = '<p>Hello World!</p>';
       return $i;
       } 
       add_shortcode('my-shortcode', 'my_shortcode_function');
       ```
   
 * Obviously I’d change hello world to make sure it reads with my info, but in this
   example, I would use [my-shortcode]
 * so, in my attempt to edit this I would do it like this.
 *     ```
       function var_FSL_function() { 
       $name = '<p>700+</p>';
       return $i;
       } 
       add_shortcode('varFSL', 'var_FSL_function');
       ```
   
 * Is that correct?
    I will plug this into functions.php and then use the [varFSL]
   where I need it. Correct?
 * Thank you in advance!! I’m so sorry I’m not a coder, but I promise, I’m trying
   like mad!!
    -  This topic was modified 4 years, 3 months ago by [hemjesti](https://wordpress.org/support/users/hemjesti/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcreating-a-variable-for-a-shortcode%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Thread Starter [hemjesti](https://wordpress.org/support/users/hemjesti/)
 * (@hemjesti)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/creating-a-variable-for-a-shortcode/#post-15368917)
 * So, after testing it out, I had to put the $i back in there. And wound up using
   this code here for each of the four variables i needed. Thank you guys for taking
   a look and i hope this helps someone else down the road. Us non-coders have to
   stick together, or get busy coding!
 *     ```
       /* variables for global variable counts */ 
       // Add Shortcode
       function var_FSL_function() { 
       $i = '700+';
       return $i;
       } 
       add_shortcode('varFSL', 'var_FSL_function');
   
       // COUNTRIES
       function var_Countries_function() { 
       $i = '140+';
       return $i;
       } 
       add_shortcode('varCountries', 'var_Countries_function');
   
       // SAME DAY DELIVERIES
       function var_SameDay_function() { 
       $i = '90K';
       return $i;
       } 
       add_shortcode('varSameDay', 'var_SameDay_function');
   
       // NEXT DAY DELIVERIES
       function var_NextDay_function() { 
       $i = '450K';
       return $i;
       } 
       add_shortcode('varNextDay', 'var_NextDay_function');
       ```
   
 * and to insert into the page copy, you would use [] and the variable – for example[
   varSameDay]
 * We have over [varSameDay] deliveries.
 * all the best to you guys!

Viewing 1 replies (of 1 total)

The topic ‘Creating a Variable for a Shortcode’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [hemjesti](https://wordpress.org/support/users/hemjesti/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/creating-a-variable-for-a-shortcode/#post-15368917)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
