Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get option

This page redirects to an external site: https://developer.wordpress.org/reference/functions/get_option/

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

<code style="color: #000000"> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #0000BB">$option</span><span style="color: #007700">, </span><span style="color: #0000BB">$default </span><span style="color: #007700">); </span><span style="color: #0000BB">?></span> </code>

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

<code style="color: #000000"><span style="color: #0000BB"><?php

$no_exists_value </span><span style="color: #007700">= </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #DD0000">'no_exists_value' </span><span style="color: #007700">);
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">( </span><span style="color: #0000BB">$no_exists_value </span><span style="color: #007700">); </span><span style="color: #FF8000">/* outputs false */

</span><span style="color: #0000BB">$no_exists_value </span><span style="color: #007700">= </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #DD0000">'no_exists_value'</span><span style="color: #007700">, </span><span style="color: #DD0000">'default_value' </span><span style="color: #007700">);
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">( </span><span style="color: #0000BB">$no_exists_value </span><span style="color: #007700">); </span><span style="color: #FF8000">/* outputs 'default_value' */

</span><span style="color: #0000BB">?></span></code>

Show Blog Title

Displays your blog's title in a <h1> tag.

<code style="color: #000000"> <h1><span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #DD0000">'blogname' </span><span style="color: #007700">); </span><span style="color: #0000BB">?></span></h1> </code>

Show Character Set

Displays the character set your blog is using (ex: UTF-8)

<code style="color: #000000"> <p>Character set: <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #DD0000">'blog_charset' </span><span style="color: #007700">); </span><span style="color: #0000BB">?></span> </p> </code>

Retrieve Administrator E-mail

Retrieve the e-mail of the blog administrator, storing it in a variable.

<code style="color: #000000"> <span style="color: #0000BB"><?php $admin_email </span><span style="color: #007700">= </span><span style="color: #0000BB">get_option</span><span style="color: #007700">( </span><span style="color: #DD0000">'admin_email' </span><span style="color: #007700">); </span><span style="color: #0000BB">?></span> </code>

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

  • Since 1.5.0

Source File

get_option() is located in wp-includes/option.php.

Related

See also index of Function Reference and index of Template Tags.