Home Forums Front-end Issues WordPress Multisite – Domain Mapping issue


WordPress Multisite – Domain Mapping issue

  • Hello,

    Love ACF, however have had some issues when using ACF with a multisite network running domain mapping using this Domain Mapping plugin.

    On our network we have two domains pointed to the same site in the network (e.g. and, however only one of those is available from outside our network (

    The issue is when using the get_field function the URL returned for images is always for the same (primary – domain, rather than using the domain we are viewing it from (

    Any advice on this would be great!


  • Hi @martinrp

    I;m not sure what the exact solution is, but I can point you in the right direction.

    ACF saves the image data as the attachment ID. This means the URL is generated dynamically when you use the get_field function.

    ACF image field uses the wp_get_attachment_image_src function to load the image url data.

    perhaps there is some documentation with the Domain mapping plugin which talks about using image functions like these?

    Hope that helps


  • Hi Elliot, thanks for the pointers, I will take look into those functions.


  • Hi @martinrp

    Let me know what you find. I’m quite interested to see how the domain mapping plugin can integrate with WP images.


  • Hi @martinrp,

    Im not sure if you have the same issue as me. But I get “sites/0/” in my attachment URLs. If you have the same issue, then use following code in your functions.php.

    add_filter('wp_get_attachment_image_src', 'acf_multisite_upload_fix', 10, 4);
    function acf_multisite_upload_fix($image, $attachment_id, $size, $icon){
    	global $current_blog;
    		$replace = $current_blog->blog_id > 1 ? 'sites/' . $current_blog->blog_id . '/' : '';
    		$image[0] = str_replace('sites/0/', $replace, $image[0]);	
    	return $image;
  • Thanks, @herkules:

    I took what you did and amended slightly. This version offloads the domain replacing part to the MU Domain Mapping plugin:

    add_filter('wp_get_attachment_image_src', 'acf_multisite_url_fix', 10, 4);
    function acf_multisite_url_fix($image, $attachment_id, $size, $icon){
    	if( isset($image[0]) ){
    		$image[0] = domain_mapping_post_content( $image[0] );
    	return $image;
  • Thanks everyone for your code samples here, I found that if an image has a srcset the solution only provides a correct URL for the default image not the others.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘WordPress Multisite – Domain Mapping issue’ is closed to new replies.