Shared functions.php across multiple WordPress websites

If your functions can go in a single file (no images, or linked js/css files), you could add them to mu-plugin file. See the Must Use Plugins page on Codex for more information.

EXAMPLE:

<?php
/*
Plugin Name: CommonCodes
Plugin URI: http://you.com/
Description: A common use file
Version: 1.0
Author: You
Author URI: http://you.com/
*/

function remove_dashboard_widgets() {
    global $wp_meta_boxes;
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
if (!current_user_can('manage_options')) {
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
}

function all_settings_link() {
    add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
    add_action('admin_menu', 'all_settings_link');

?>

You would then just save it as commonfunctions.php or whatever. Create a folder in the wp-content directory called mu-plugins and place the single PHP file in that folder. It will auto-activate, and can’t be removed from the WP-Admin area.

Any issues you might face would depend on the plug-ins or themes that could possibly re-use the same functions causing a conflict.

Leave a Comment