avatar Deluxe Blog Tips About Projects

Script to update option on all sites in a WordPress multisite

I recently faced a situation where I want to change the footer text on all demos of my TheM theme. Each demo is a child site of a WordPress multisite network. I can do that easily by going to each site and update the theme option. The problem is if I need to update once more time or change another option, I need to repeat the procedure all over again. It takes a lot of time then. So I write this small snippet to update theme option on all child sites of a multisite network. You can use that to update post content or anything.

Here is the snippet:

ini_set( 'display_errors', 1 );
include 'wp-load.php';

$sites = get_sites();

// Show all sites info
echo '<pre>';
print_r( $sites );
echo '</pre>';

foreach ( $sites as $site ) {
    // Only update needed sites
    if ( false === strpos( $site->path, 'them' ) ) {

    switch_to_blog( $site->blog_id );

    // Restore footer text to default
    echo 'Updating footer for site: ', $site->path, '<br>';
    remove_theme_mod( 'footer_text' );

    // Do whatever you want

echo 'Done';

Save it as a PHP file and upload to your WordPress root (same folder as wp-config.php), then run it from your browser.

Feel free to improve it to work with your needs. Hope this snippet can save you some time :).

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com