V
V
VANY2015-12-12 19:37:53
WordPress
VANY, 2015-12-12 19:37:53

Wordpress Multisite - how to execute code for only one site?

How to write code in functions.php (calling some function) so that it is executed only for a specific network site ID?
Similarly - how to call a php variable on one site from another network site (for example, the main one)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2015-12-14
@HeadOnFire

Code isolation for one site:

global $blog_id;
if( $blog_id == 1 ) {
    // код, который должен выполняться только для сайта с ID=1
}
// или
$blog_id = get_current_blog_id();
if( $blog_id == 1 ) {
    // код, который должен выполняться только для сайта с ID=1
}

Gaining access to another site's data:
$blog_id = 2;
switch_to_blog( $blog_id );
    // Выполнить нужные действия
restore_current_blog();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question