views:

41

answers:

2

How/Where can I store some values such as a phone number or email address so I can use these values on any page in a my custom theme?

Example: I want to store a contact phone number that should be displayed in the header file of my theme but i dont want to hardcode it into the html. I would like to store it in a simerlar way custom values are stored but accessable from any theme page.

A: 

You have a couple options. One would be just add methods to the function.php files of your theme and call those with php wherever you need Ex: in functions.php you could add

function get_contact_number() { return "555-555-5555"; } and then whenever you want to display it just call <?= get_contact_number()?>

Or, even simpler, just add them as unique variables to functions.php and echo those out where you need to.


A more complex route would be to use the options table in wordpress. In which case you would either insert it manually into the database, or run the method update_option('custom_name','custom_value') (which handles both updating and creation) in one of your theme files. Then you would display the option with get_option('custom_name').

derrickp
+3  A: 

Use get_option and update_option to store your settings in the WordPress database. Then you'll be able to update the options using the wp-admin/options.php screen (you'll have to type that in, there's no menu option) or using one of these plugins:

Later you can create custom option pages for greater control.

And don't forget to use escaping functions when rendering the options in templates.

Chancey Mathews