0

I have added Facebook fanbox to my site but it causes performance problems. Is there a plugin that embeds the fanbox and loads the javascript in the footer and asynchronously (if possible)? If not, can I do it manually somehow? I want to load the js file from the footer but the fanbox to appear in an upper section of the page.

Thanks in advance

1

You can use the asynchronous XFBML javascript but you have to register an app and get an appID.

Here is the function I use to add the XFBML to the footer. Note: This will work for the like button also.

add_action('wp_footer', 'c3m_share_this_scripts' );
function c3m_share_this_scripts() {
    echo    '               <script>';
            echo        "               window.fbAsyncInit = function() {;
                        FB.init({appId: 'xxxxxxxxxxxxxxx', status: true, cookie: true,
                                xfbml: true});
                                };";
            echo        "                 (function() {
                                        var e = document.createElement('script'); e.async = true;
                                        e.src = document.location.protocol +
                                          '//connect.facebook.net/en_US/all.js';
                                    document.getElementById('fb-root').appendChild(e);
                                      }());
                                    </script>";
}

Replace the xxxxx's with your appID

Now to add the like box:

function c3m_facebook_likebox() {
         echo '<fb:like-box href="http://www.facebook.com/your_page_url" width="292" colorscheme="dark" show_faces="true" stream="true" header="true"></fb:like-box>';
}

You can hook the above function into a content hook or just add the c3m_facebook_likebox(); template tag where you want it to show up.

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.