The is_main_blog() WordPress PHP function is a deprecated function used to determine if the current site is the main site. You should use is_main_site() instead.
Usage
if (is_main_blog()) { // Do something if the current site is the main site }
Parameters
- None
More information
See WordPress Developer Resources: is_main_blog
This function is deprecated. Use is_main_site() instead.
Examples
Display a message on the main site
This example checks if the current site is the main site and displays a message.
if (is_main_blog()) { echo 'This is the main site!'; }
Redirect users to the main site
This example redirects users to the main site if they’re not already there.
if (!is_main_blog()) { wp_redirect(get_main_site_url()); exit; }
Display a specific widget on the main site only
This example shows how to display a specific widget only on the main site.
if (is_main_blog()) { dynamic_sidebar('main-site-sidebar'); }
Load a specific stylesheet for the main site
This example shows how to enqueue a specific stylesheet only for the main site.
function load_main_site_stylesheet() { if (is_main_blog()) { wp_enqueue_style('main-site-style', get_template_directory_uri() . '/main-site.css'); } } add_action('wp_enqueue_scripts', 'load_main_site_stylesheet');
Display specific navigation menu for the main site
This example shows how to display a specific navigation menu only on the main site.
function display_main_site_menu() { if (is_main_blog()) { wp_nav_menu(array('theme_location' => 'main-site-menu')); } else { wp_nav_menu(array('theme_location' => 'other-sites-menu')); } } display_main_site_menu();