Fixed: The fb-root div has not been created & FB.getLoginStatus()

If you add some Facebook widget to website, this error might appear on console: The fb-root div has not been created, auto-creating
Even though it might not break your site, it’s annoying and best to solve it. So, how to do it:

When you add for example Facebook like box, you add Javascript that upon loading page searches for div with id fb-root and then inserts Facebook widget. In this case, your website have no fb-root div so it’s created automatically hence the auto-creating in the warning. To solve this, simply add div with id fb-root to your website’s template. I usually insert this code before place where the Facebook widget will be.
Full code is

<div id="fb-root"></div>

FB.getLoginStatus() called before calling FB.init().

And while we are fixing errors related to Facebook, let’s fix this. It’s very common error, fortunately it’s easy to solve. Simply add &status=0 , when including javascript.

js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1<strong>&status=0</strong>";

Change en_GB to your language code is necessary.


<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&status=0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

I hope these little tips helped you to solve ‘fb-root div has not been created’ and ‘FB.getLoginStatus’ problems. What other Facebook errors do you face upon creating/updating website? Feel free to leave them in comments!