This page redirects to an external site: https://developer.wordpress.org/reference/functions/get_option/
Languages:
English •
Español •
Italiano •
日本語
Русский •
Tiếng Việt •
中文(简体) •
(Add your language)
Description
A safe way of getting values for a named option from the options database table. If the desired option does not exist, or no value is associated with it, FALSE will be returned.
Usage
<?php echo get_option( $option, $default ); ?>
Parameters
- $option
- (string) (required) Name of the option to retrieve. Underscores separate words, lowercase only.
- Default: None
A concise list of valid options is below, but a more complete one can be found at the Option Reference.
- 'admin_email' - E-mail address of blog administrator.
- 'blogname' - Weblog title; set in General Options.
- 'blogdescription' - Tagline for your blog; set in General Options.
- 'blog_charset' - Character encoding for your blog; set in Reading Options.
- 'date_format' - Default date format; set in General Options.
- 'default_category' - Default post category; set in Writing Options.
- 'home' - The blog's home web address; set in General Options.
- 'siteurl' - WordPress web address; set in General Options.
Warning: This is not the same as get_bloginfo('url') (which will return the homepage url), but as get_bloginfo('wpurl').
- 'template' - The current theme's name; set in Presentation.
- 'start_of_week' - Day of week calendar should start on; set in General Options.
- 'upload_path' - Default upload location; set in Miscellaneous Options.
- 'users_can_register' - Whether users can register; set in General Options.
- 'posts_per_page' - Maximum number of posts to show on a page; set in Reading Options.
- 'posts_per_rss' - Maximum number of most recent posts to show in the syndication feed; set in Reading Options.
- There are many more options available, a lot of which depend on what plugins you have installed.
- $default
- (mixed) (optional) The default value to return if no value is returned (ie. the option is not in the database).
- Default: false
Return Values
- (mixed)
- Current value for the specified option. If the option does not exist, returns parameter $default if specified or boolean FALSE by default.
Examples
<?php
$no_exists_value = get_option( 'no_exists_value' );
var_dump( $no_exists_value ); /* outputs false */
$no_exists_value = get_option( 'no_exists_value', 'default_value' );
var_dump( $no_exists_value ); /* outputs 'default_value' */
?>
Show Blog Title
Displays your blog's title in a <h1> tag.
<h1><?php echo get_option( 'blogname' ); ?></h1>
Show Character Set
Displays the character set your blog is using (ex: UTF-8)
<p>Character set: <?php echo get_option( 'blog_charset' ); ?> </p>
Retrieve Administrator E-mail
Retrieve the e-mail of the blog administrator, storing it in a variable.
<?php $admin_email = get_option( 'admin_email' ); ?>
Notes
- Uses: apply_filters()
- Calls 'pre_option_$option' before checking the option. Any value other than false will "short-circuit" the retrieval of the option and return the returned value. You should not try to override special options, but you will not be prevented from doing so.
- Calls 'option_$option', after checking the option, with the option value.
- Calls 'default_option_$option' to filter $default before returning it if it is set and the value doesn't exist.
- Uses: maybe_unserialize() to unserialize the value before returning it.
Changelog
Source File
get_option() is located in wp-includes/option.php.
Related