Support » Plugins » Hacks » Run a Function to Set Globals the First Time a User Enters Site

  • Hi all,

    Short Story – I have a site where I’d like to run a function and set some globals for a visitor’s first page load. It should be run before the theme is visually loaded (as the theme uses that information).

    I’ve tried putting it into functions.php and doing an add_action(‘init’, ‘my_function’) as well as add_action(‘plugins_loaded’, ‘my_function’) but that function was run sporadically at best.

    I can’t find a consistent place to do this, so I put it on the top of header.php which means it gets run EVERY page view – probably not the most efficient.

    Long Story – I am doing geotargeting. I have a function that checks if the user is Australian, and if they are, show them the Australian store that I’m affiliated with. This is using geoplugin.com’s geotargeting class and a plugin PHP file I created in the plugins folder. I’m simply running that plugin function each time, getting a global countryCode, and changing a $buyURL if $countryCode is “AU”.

    If there’s better ways of doing this without running this function at EVERY header.php load, I’d love to hear them. Perhaps set a cookie somewhere?

    This is for my Jack3d site. Australians can let me know if it’s working 🙂

    Thanks!

Viewing 1 replies (of 1 total)
  • Hi MicroBerto, I`ve been looking for the exact same thing. Did you find an answer to your question?
    Thanks,
    Thierry

Viewing 1 replies (of 1 total)
  • The topic ‘Run a Function to Set Globals the First Time a User Enters Site’ is closed to new replies.