how can I load switch_to_blog() function outside wordpress?

$blog_id = '7';
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
echo get_option('blogname');
echo 'You switched back.';

I get error:

Fatal error: Call to a member function set_prefix() on a non-object in /home/public_html/wp-includes/ms-settings.php on line 126

Any ideas ?

UPDATE It can be loaded but without any function just this code ? What global variables is missing ?

1 Answer 1


This may not be possible.

From the Codex page Integrating WordPress with your Website, which explains how to use WordPress "outside" of WordPress:

These directions will not work on a MultiSite Network.

  • Yes I have tried but I guess where is some method.
    – andys
    Nov 7, 2014 at 9:48

Your Answer

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

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