Doesn't VB4 have facebook integration built in already? You just go to the admin cp -> vbulletin options -> Facebook Options to set it up...
If you are using VB3.x then I recommend this mod, it's what I use in my 3.8 board:
https://vborg.vbsupport.ru/showthread.php?t=243319
For the most part it would work on VB4 if it had to, just put the code in SHOWTHREAD so you don't need those conditionals.