I was working on a WordPress site today with social buttons for each post on archive pages. The site also has AJAX pagination that appends posts to the page when you click ‘view more’. The issue I ran into was when new content came in via AJAX, the social buttons in HTML and XFBML weren’t rendering their iframes or complete content. They were just the placeholders specified in the source.
So here are three snippets to remember for Facebook, Twitter and ShareThis buttons:
Facebook is simple. It’s just a call to its XFBML parser.
Share this is also simple.
Twitter had a similar method in the past, but in new versions of their code the method was dropped. So now you just have to reload the Twitter JS. Not graceful, but it works.
var twitterWidgets = document.createElement(’script’);
twitterWidgets.async = true;
twitterWidgets.src = ‘http://platform.twitter.com/widgets.js’;
I know I’m going to use these again. So here they are. Hopefully, this cures someone else’s headache in the future.