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 ?
If you save those urls in options table, then using get_option you can use it any where...
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:
- Edit your template's
functions.php; create it if there isn't any.
- There, you can either, use
add_optionin the global context or add some hook like
'after_setup_theme'to have control over order of its execution.
Either way, write something like this in your
add_option('login_url', 'some/url'); add_option('register_url', 'some/other/url');
This will initialize your desired variables.
Then, in your widgets and page templates you can use
get_optionfunction to get retrieve these values:
You can find documentation to these functions here: add_option