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 ?
2 Answers
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_option
in 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
functions.php
: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_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.– kaiserCommented Apr 4, 2012 at 12:15