Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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

share|improve this answer
add comment

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

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
add comment

Your Answer

 
discard

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.