I am currently developing a multi-site plug-in for WordPress. I need to run a function when a new site is created.

2 Answers 2


I guess you are looking for an action/filter.

wpmu_new_blog this action is fired in wpmu_create_blog function (wp-includes/ms-functions.php)

do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
  • I need to run my custom function when a new site is created Feb 25, 2013 at 6:02
  • I need to teach you how to hook action?
    – Jesse
    Feb 25, 2013 at 6:02
  • if possible can u ? Feb 25, 2013 at 6:04
  • 1
    Actions and filters are the fundamental knowledge of wordpress plugin development. Hooking an action is the most basic stuff. If you have no idea what they idea, I would suggest googling about add_action first.
    – Jesse
    Feb 25, 2013 at 6:12

Since WP 5.1.0, wpmu_new_blog has been deprecated in favour of wp_insert_site:

 * Fires once a site has been inserted into the database.
 * @since 5.1.0
 * @param WP_Site $new_site New site object.
do_action( 'wp_insert_site', $new_site );

Use it like this in your plugin or theme:

add_action('wp_insert_site', function($site) {
  // do something

A good place to look for available hooks is wp-includes/ms-default-filters.php

wp_insert_site on WordPress Developer Handbook

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.