Having a custom functions or styles per individual WordPress multisite site

If you find this free website useful – why don’t you support this with a donation? It is easy…. read more ….

If you are running a multi-site and you a have common theme sometime is becomes a requirement to add specific styling and functions for an individual site or two.

The traditional way is to create a child theme and apply that to the site, and this works fine, but this method allows you to create individual functions or css per site easily and relatively quickly.

The idea is that within the theme  (actually  a child theme as you don’t want to be updating the functions.php of a parent theme as you will end up losing you customisations on updates  see http://codex.wordpress.org/Child_Themes ) to add some code to functions.php  that uses the child theme folder.

So we create   wp-content/childthemename/blogs/{id}

where {id} is the blog id  and add a functions.php in that directory

With the code below, at the top of your functions.php  (after comments) this file will be picked up and executed just for the specific multi-site.

 

/* do specific functions.php for specific blogs */
if ( is_multisite() && file_exists( get_stylesheet_directory() . '/blogs/'.get_current_blog_id().'/functions.php' ) ) {
		require( 'blogs/'.get_current_blog_id().'/functions.php' );
		}

 

<?php
function theme_name_scripts() {
  if ( is_multisite() && file_exists( get_stylesheet_directory() . '/blogs/'.get_current_blog_id().'/style.css' ) ) {	
	wp_enqueue_style( 'custom-blog-style', get_stylesheet_directory_uri(). '/blogs/'.get_current_blog_id().'/style.css' );
  }
}
	
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
?>

 

Most themes have an inbuild CSS option but if not you could also  try this, it should work, but this code is currently untested

 

 


Posted

in

,

by

Tags:

Comments

Leave a Reply

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