3

I have 2 websites http://www.aaa.com and http://www.bbb.com and need them to show the same.

Now I put an iframe in index.html and upload to aaa.com. It's ok for frontend but it's doesn't work for backend, where it shows a blank page.

Can anyone suggest me how I can solve this problem ?

  • hmmm this doesn't seem like the best approach to making this work, have you looked into multisite and domain mapping? – Tom J Nowell Apr 19 '12 at 9:34
3

By default WordPress sends an HTTP header to prevent iframe embedding on /wp_admin/ and /wp-login.php:

X-Frame-Options: SAMEORIGIN

That's a security feature. If you want to remove this header remove the filters:

remove_action( 'login_init', 'send_frame_options_header' );
remove_action( 'admin_init', 'send_frame_options_header' );

But you should really use the multisite feature as Tom J Nowell suggested.

  • Thanks Tom and toscho :) the problem is I cannot control domain or anything in aaa.com, just ftp I can use for transfer files to site and it's not work properly on IIS server and sure admin cannot fix for me. so i decide to move to my hosting that I can control and it's Apache. everything works fine with iframe except backend :( did you guys have some suggestion ? thank you very much :D – toonztudio Apr 21 '12 at 2:55
3

Tried to extend the version of @toscho

    //remove the restriction
    remove_action( 'login_init', 'send_frame_options_header' );
    remove_action( 'admin_init', 'send_frame_options_header' );

    //for added security
    add_action( 'login_init', 'Access_Control_Allow_Origin' );
    add_action( 'admin_init', 'Access_Control_Allow_Origin' );


    function Access_Control_Allow_Origin(){
        $origin=get_http_origin();
        $allowed_origins=array(//add your domains or keeps empty
            "aaa.com",
            "bbb.com",
        );
        $allowed=false;
        if(count($allowed_origins)>0){
            foreach($allowed_origins as $allowed_origin){
                if (strstr($origin,$allowed_origin)){
                    $allowed=true;
                    break;
                }
            }       
        }else{
            $allowed=true;
        }
        if($allowed){
            return true;
        }else{
            send_origin_headers();
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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