You could use get_sites
function which takes many arguments one of which happens to be count
argument which allows get_sites
function to return a site count.
According to the official documentation, get_sites
function returns the number of sites when 'count' is passed.
"this counter must increase or decrease every time a new site is open or closed."
Also in order to get a real-time counter you could use wp_head
action hook! Which means every time that wp_head
fires, which is on every page load, you get an update. Depending on how you would want to set this up, you could use ajax
too which allows you to get an update without even refreshing/reloading the page.
So to start with, we could combine get_sites
function, count
argument and wp_head
hook to get what you're looking for! Like this:
This code goes into the functions.php
of your active theme.
add_action('wp_head', 'your_mutisite_counter', 99);
function your_mutisite_counter(){
$args = array(
'count' => true
);
$number_of_sites = get_sites( $args );
echo $number_of_sites;
}
If you want to know more, I strongly suggest to go and read the documentation pages, specially when you scroll down the page, there are very good examples from community members and developers which could be very helpful.
get_sites
Docs
Also if you want to know what kind of arguments get_sites
function accepts, in addition to count
, here's the official documentation:
arguments
Docs
Hopefully all of this would give you a place to start with!!!