Search

Set Default Theme, Logo and Menu for Subsites in WordPress Multisite

Listen to this article

same-theme-for-wordpress-multisiteIf you asked me whether all sites in a WordPress multisite should be similar, my answer would be ‘No’. All sites need not be similar. If you wanted a multisite network to have the same theme but only differ in content, I’d suggest using custom post types or taxonomies, as a simpler approach to tackle this requirement. But there are exceptions. Having a multisite for this scenario makes sense when you want to have a one-click option to create different sites for each franchise, setup in different locations.

What usually happens is that a business owner has a particular site, and wants to have the same look and feel for subsites. So say you are ‘Blueleaf Inc.’. And you offer franchises. Now, if you want each franchise to have its own website, but still control the themes and plugins which can be used, you can proceed with WordPress multisite. Your site will be the main site in the network, and each site for a franchise will be a subsite. Since you have to preserve your brand, it is understood that your theme will be the same.

For WordPress developers a theme is used for styling your website- setting layouts, the header, the footer. For site owners, the idea could go a step further. Applying the same theme across subsites could mean having the same logo and navigation menu as well. That’s perfectly understandable.

So what would like to achieve here is:

  • The same theme applied across all sites
  • The company’s logo placed in the header of every subsite
  • A default navigation menu for all subsites

The ideal case would be, if a store bought theme would suffice our need. You would then just need to activate the theme across all sites. But that would be close to impossible. You wouldn’t have a theme custom built for you- that too with your logo! What you would have to do is make a few changes in the theme you decide to use for your websites.

Since every theme might have different hooks, I can’t list out a solution for every theme possible. As an example, I will provide a solution for Genesis child themes, since the solution will be applicable to any Genesis child theme you choose.

[space]

Setting a Default Theme for all Subsites in a WP Multisite

I’m assuming you have decided upon a theme, you would like to have for your websites. Maybe you have it applied on your main site already. If this theme is the only theme available on your main site, and network available, you would assume that it would be automatically set for your subsites. But this is not the case. WordPress will try and apply a default theme. So WordPress 4.1 will try to search for the TwentyFifteen theme, and try and apply it. If it does not find the theme, it will report an error, but your theme will not be applied.

What we can do here, is follow an approach which will ensure that our theme is set as the default theme and will be applied for all subsites. This can be accomplished by a simple one line code, in your wp-config.php file. You could add it anywhere, but before wp-settings.php file is included.

define( 'WP_DEFAULT_THEME', 'your-theme-name' );

Just replace your-theme-name with the name of your theme. This line of code will ensure that your theme is enabled by default. This will work not only for Genesis themes but for any WordPress theme.

[space]

Setting a Default Logo for all Subsites in a WP Multisite

Next, we’ll try to set the same logo for all subsites. For this, I cannot provide a generic approach since every theme will have different settings. This approach can be used for Genesis themes. If you’ve read this article ‘How to Change the Logo in Genesis Child Theme’, you’ll know that you can set the logo programmatically. The logo can be set as the background image in your header. We’ll use this same approach to set the logo across all child themes.

If you add the below code in style.css of your theme, this logo will be automatically displayed across all subsites when the theme is activated. However, if you do not want to make any changes in your theme, you’ll have to create a custom plugin and add the code there. Be sure to network enable the plugin so that the changes are applied to all sites.

  1. Upload the logo image in your main site. Let’s assume you’ve named it mylogo.
  2. Get the absolute url of the image, and use this in your CSS.
.header-image .site-header .site-title a {
   background: url(http://main.com/wp-content/uploads/2015/01/mylogo.png) no-repeat left;
   padding: 0;
}

Providing styling for a specific attribute ensures that the changes will be applied.

[space]

Setting a Default Menu for all Subsites in a WP Multisite

If you want to set a default menu, this would mean you would want to have certain pages created as well. This could be complicated but not impossible. Let’s consider that we have to add a homepage and a ‘Home’ link in the primary navigation menu (you can similarly add additional pages). The below code can be added to functions.php of your Genesis child theme. If you wanted to add the code in a custom plugin, you would have to make the plugin multisite compatible and then tweak the code and add it.

// add a function which will be called when a new site is created
add_action( 'wpmu_new_blog', 'create_menu_on_site_creation' );

function create_menu_on_site_creation( $blog_id ) {
    switch_to_blog( $blog_id );

    $menu_name = 'Primary Menu';
    $menu_exists = wp_get_nav_menu_object( 'Primary Menu' );

    // If no menu is set as the Primary menu and a menu with name 'Primary Menu’ does not exist
    // we have to create a Primary Menu
    if ( ! has_nav_menu( 'primary' ) && ! $menu_exists ) {
        $menu_id = wp_create_nav_menu( $menu_name );
        // Add Home as default link in the menu
        wp_update_nav_menu_item( $menu_id, 0, array(
        'menu-item-title' => __( 'Home' ),
        'menu-item-classes' => 'home',
        'menu-item-url' => home_url( '/' ),
        'menu-item-status' => 'publish' ) );

        // Assign menu to Primary location
        $locations = get_theme_mod( 'nav_menu_locations' );
        $locations[ 'primary' ] = $menu_id;
        set_theme_mod( 'nav_menu_locations', $locations );
    }
    restore_current_blog();
}

This will work for Genesis child themes as well as WordPress themes which have ‘primary’ as the Primary Menu navigation id.

[space]

One thing you should know, is that this code works for Genesis child themes, but the idea would work for any WordPress theme (the hooks will differ though). If you would want certain templates to be applied for pages created, this can be done as well, but this would be a better topic for another day. What I would like to know, is your thoughts on this idea, and if you had any suggestions or questions. Do feel free to leave your comments and feedback in the comment section below.

Sumit Pore

Sumit Pore

Leave a Reply

Your email address will not be published. Required fields are marked *

Get The Latest Updates

Subscribe to our Newsletter

A key to unlock the world of open-source. We promise not to spam your inbox.

Suggested Reads

WordPress Development

Custom WordPress Solutions, for You

LearnDash Development

Custom LearnDash Solutions, for You

WooCommerce Development

Custom WooCommerce Solutions, for You

WordPress Plugins

Scale your WordPress Business

WooCommerce Plugins

Scale your WooCommerce Business

LearnDash Plugins

Scale your LearnDash Business

Label

Title

Subtext

Label

Title

Subtext

Join our 55,000+ Subscribers

    The Wisdm Digest delivers all the latest news, and resources from the world of open-source businesses to your inbox.

    Suggested Reads