WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a widget where I set some custom url's like register or login. I want to use those variables declared in a widget outside of the widget, in other pages (page templates). How can I save or use, for example, $login or $register variables, in other pages ?

share|improve this question

If you save those urls in options table, then using get_option you can use it any where...

share|improve this answer

If you post relevant codes here (like your widget), it would help us answer more appropriately. Anyway, here's my suggestion based on Rajeev Vyas's answer:

  1. Edit your template's functions.php; create it if there isn't any.
  2. There, you can either, use add_option in the global context or add some hook like 'after_setup_theme' to have control over order of its execution.
  3. Either way, write something like this in your functions.php:

    add_option('login_url', 'some/url');
    add_option('register_url', 'some/other/url');

    This will initialize your desired variables.

  4. Then, in your widgets and page templates you can use get_option function to get retrieve these values:


You can find documentation to these functions here: add_option

share|improve this answer
I'd recommend to use a prefix for those options. If you're not deleting them on uninstall, no one will ever be able to tell if these are core options or left over options. – kaiser Apr 4 '12 at 12:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.