0

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 ?

1

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

0

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:

    get_option('login_url');
    get_option('register_url');
    

You can find documentation to these functions here: add_option

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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