Network Plugin Creating Pages for Different Subdomains

You can’t find the option to specify the domain because there isn’t one, that’s not how multisite work. Functions always operate on the current site. If you’re in WP Admin the site is the site that WP Admin is for.

Additionally, the plugin will run on all sites, so if your code worked the way you think it does, and you have 5 sites, you’d get 5 duplicate pages.

Finally, your code as is will create a page on every single request. AJAX requests, cron jobs, REST API endpoints, etc. Simply being in a post edit screen will create a page from the WP Heartbeat mechanism.

So there are a few things to note:

  • Don’t create pages on init or admin_init
  • Create the pages on site creation or plugin activation
  • Only create the page when you’re on the site you want to create the page on

You can change the current blog using switch_to_blog and passing a site ID, and then restore_current_blog to undo it, but keep in mind that this doesn’t avoid the duplication bug I pointed out above.

So the gist is:

if ( on the site I want it on ) {
    create the page
}

So grab the current homepage and check if using standard string comparisons, e.g:

if ( site_url() == 'https://example.com' )

Otherwise if you already know the page content, and you already know which domain it’s going on, why write it in code when you can write it in WP Admin? There doesn’t seem to be a point to doing it the way you’re doing it ( unless there’s more to your question you’ve not shared with us )