Common custom template across all themes

Does any one know whether it is possible to create one set of custom template files that will be applied across all active themes?

Case in point is I have the 133 theme pack installed (so 133 themes are active). If I want to customize footer.php for example, I have to edit footer.php in 133 places. I was wondering whether one can add a custom footer.php on one place, which would override the footer.php for each of the 133 themes without having to edit footer.php in each theme directory?

I found a way to do this for adding custom functions in fuctions.php across all themes using the "mu-plugins" (must use plugins) directory in the plugins folder as described in this post, which I found very useful. I was wondering whether there might be something similar for themes?

P.S. I am sure there are better ways of customizing the footer than overriding the template - this was just an example (I need to do far more extensive overriding of templates - mostly adding new ones, which do not already exist and I would prefer not to have to add them to each theme directory if possible).

Thanks.

  • Philip John

    Hiya!

    There is a way, yes but it won't work with 133 themes pack.

    Basically, you'd need all of your themes to be child themes of one parent theme. You could then simply update the parent and all the child themes would follow suit.

    That's not possible with 133 because they are all effectively parent themes themselves with varying code which you'd have to redevelop for each one just to try and achieve that.

    Sorry it's not better news!

    Phil

  • BlueSea

    Okay thanks. I wrote some php code to deploy files to all theme directories if any one else needs something similar (see below).

    Warning: The script does very little checking so use at your peril (it will overwrite stuff you may not intend if not careful).

    <?php
    
    /*
    Deploy files to theme directories
    */
    
    define('WORDPRESS_PATH', '/var/www/html');
    
    //Get lists of files to deploy
    $customThemeFilePath = WORDPRESS_PATH . "/../CustomThemeFiles";
    $filesToDeploy = array();
    
    if ($handle = opendir($customThemeFilePath)) {
        echo "Files to deploy:\n";
    
        while (false !== ($file = readdir($handle))) {
      		if ($file != "." && $file != ".." && is_file("$customThemeFilePath/$file") && $file != $argv[0]) {
            	echo "$file\n";
            	//Build list of files to deploy
            	$filesToDeploy["$file"] = "$customThemeFilePath/$file";
            }
        }
    
        closedir($handle);
    }
    
    //Get list of theme directories to deploy to
    $themeDirectoryPath = WORDPRESS_PATH . "/wp-content/themes";
    $directoriesToDeployTo = array();
    
    if ($handle = opendir($themeDirectoryPath)) {
        echo "Directories to deploy to:\n";
    
        while (false !== ($dir = readdir($handle))) {
      		if ($dir != "." && $dir != ".." && is_dir("$themeDirectoryPath/$dir")) {
            	echo "$dir\n";
            	//Build list of directories
            	array_push($directoriesToDeployTo, "$themeDirectoryPath/$dir");
            }
        }
        closedir($handle);
    }
    
    //Deploy files to each theme directory
    
    foreach ($directoriesToDeployTo as $deployDirectory) {
    
    	foreach ($filesToDeploy as $fileName => $completeSourceFileName) {
    		if (is_dir($deployDirectory)) {
    			if (!copy($completeSourceFileName, "$deployDirectory/$fileName")) {
    				echo "Failed to copy $completeSourceFileName to $deployDirectory \n";
    			} else {
    				echo "Successfully copied $fileName to $deployDirectory \n";
    			}
    		}  else {
    				echo "Directory does not exist: $deployDirectory \n";
    		}
    	}
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.