The get_blog_option() WordPress PHP function retrieves the value of an option for a given blog ID based on the option name.
Usage
get_blog_option($id, $option, $default_value = false);
Example:
$blog_id = 2; $option_name = 'blogname'; $default_value = 'Default Blog Name'; $blog_name = get_blog_option($blog_id, $option_name, $default_value); echo $blog_name; // Output: "Custom Blog Name" or "Default Blog Name" if not set
Parameters
- $id (int) – A blog ID. Can be null to refer to the current blog.
- $option (string) – Name of the option to retrieve. Expected to not be SQL-escaped.
- $default_value (mixed) – Optional. Default value to return if the option does not exist. Default: false
More information
See WordPress Developer Resources: get_blog_option()
Important: This function is only available if WordPress has been installed and configured as a multisite install. Check function_exists()
or use is_multisite()
before calling get_blog_option()
.
Examples
Retrieve the blog description
$blog_id = 3; $option_name = 'blogdescription'; $default_value = 'No description available'; $blog_description = get_blog_option($blog_id, $option_name, $default_value); echo $blog_description;
Retrieve the blog admin email
$blog_id = 4; $option_name = 'admin_email'; $default_value = '[email protected]'; $admin_email = get_blog_option($blog_id, $option_name, $default_value); echo $admin_email;
Retrieve the blog timezone string
$blog_id = 1; $option_name = 'timezone_string'; $default_value = 'UTC'; $timezone = get_blog_option($blog_id, $option_name, $default_value); echo $timezone;
Retrieve the blog date format
$blog_id = 5; $option_name = 'date_format'; $default_value = 'F j, Y'; $date_format = get_blog_option($blog_id, $option_name, $default_value); echo $date_format;
Retrieve the blog posts per page
$blog_id = 2; $option_name = 'posts_per_page'; $default_value = 10; $posts_per_page = get_blog_option($blog_id, $option_name, $default_value); echo $posts_per_page;