wp_get_attachment_image_src multisite issue

Some of the more archaic code is still present in WordPress, notably globalising variables inside functions. A good example of thise is get_current_blog_id(), which is present in wp-load.php:

/**
 * Retrieve the current blog ID.
 *
 * @since 3.1.0
 *
 * @global int $blog_id
 *
 * @return int Blog id
 */
function get_current_blog_id() {
        global $blog_id;
        return absint($blog_id);
}

This means that you could potentially run into issues if you set $blog_id yourself in your theme. This goes for $current_site and some other variables too.

By the sounds of your questions I’d guess you’re building a theme or plugin yourself, so there’s a good chance you’re using the above variables. Good practice is to prefix your variables with something unique to your theme.

Leave a Comment