• Hi,

    I would like to pass a custom variable from template page to function.php my current theme.

    Note: I just want to pass this value on template page load. Not using get or post method.

    Thanks,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Where is the variable defined? Can your template just call a function with a parameter and you define that function in functions.php?

    Thread Starter jaymin2web

    (@jaymin2web)

    Hello Steve Stern,

    I am using one of the plugin – to implement payment form, I am using hook to update that amount value dynamically when page load.

    That payment form, I am using in my custom page, and passing the Amount through URL of that payment page to hook I am updating the amount value when page load. Hook defined in funcion.php

    I am trying to find a solution, without passing value from URL, if I can pass the value to that hook dynamically when page load. I tried to defined Global variable but it is not working for me.

    Thanks,

    Moderator bcworkz

    (@bcworkz)

    Yeah, globals only are valid within the same request. Make a new request and all globals are forgotten. You have a few choices for storing values that persist between requests. Store as a cookie value, PHP session variable, or WP transient. Cookies work better with with JS than PHP. Transients require DB queries and are better for more extended but still temporary storage like into the following day. Thus session variables are probably your best bet.
    http://php.net/manual/en/book.session.php

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

The topic ‘how to pass custom variable from template to function.php’ is closed to new replies.