• Resolved hemjesti

    (@hemjesti)


    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 3 years, 1 month ago by hemjesti.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter hemjesti

    (@hemjesti)

    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.