Yet Another WordPress Hack

I do not very well remember how much I’ve screwed around with WordPress and its plugins, but here is one of my latest mods to an existing plugin that I believe will be very useful for users wanting to import all photos from their photo albums of a particular Facebook page. I had been searching around for plugins, and could never find one that could actually do the job. Either if a plugin could display all photos from all albums it didn’t have the feature to read from a Facebook page and was rather limited to just Facebook users, like the Fotobook plugin. Or if it could read from pages, then I had to specify each and every album ID separately in the shortcode, and add as many shortcodes as there are albums in that Facebook page. And moreover, updates in the gallery page to include the new shortcodes for newly added albums on Facebook had to be done manually. It fit in only if I wanted to display selected albums. But then I had to just display all of them, and there were more than ten albums that could possibly keep increasing every month or sooner.

And fetching the album IDs of each of those ten albums was trouble again. Say you open an album and read the URL on the address bar. You would see something like this: The number in between the first dot after ‘a’ and in between second dot becomes your album ID. And would I like to manually read each of those album IDs, and that too every time a new album is added? And then manually add it to the page in the website? No!

So I found this plugin Facebook Page Photo Gallery, but which like I said could only display based on the album ID in specific, and it required me to add each album ID manually as a shortcode:

[fbphotos id=albumid]

I liked the overall feel of the plugin, and the thumbnail style and the jQuery effects that the developer had used in his plugin. And then it was time for me to start digging into the code. I narrowed down to this function, where in he generates a string containing the HTML to be printed, which again is generated by calling the fppg_get_photos() function by passing the album ID. Here is the original piece of code from facebook-page-photo-gallery.php, starting from line 34.

/*Function to hook to an embedding shortcode 
 * @param $album array passed through shortcode

function fppg_embed_photos($album) {

static $count=0;
extract( shortcode_atts( array(
		'id' => '',
		'limit' => 300,
	), $album ) );
'; return($div); }

Great. What I needed to change was to loop over the piece of code generating the HTML for each and every album rather than just the one album. So here is what I did. This was the page of my interest:, and its ID was 286244581216. And then I went to to get the details of all albums of that particular page in JSON format.

Just a small note here, if suppose a page has a registered username and does not have its ID in the page URL, say like, then go to to retrieve its ID as one of the JSON objects.

Now that I had details of all the albums of a particular page in JSON format, the next thing that I needed to do was parse the JSON and retrieve the IDs of all the albums from the JSON, and run these album IDs in a loop through the previous code. The modified code is here, with the function fppg_embed_photos() replaced by mine.

function fppg_embed_photos($album) {

static $count=0;
extract( shortcode_atts( array(
		'id' => '',
		'limit' => 300,
	), $album ) );

/* Fetching the JSON Data from the URL */

/* Decoding the JSON Data and storing it in $fbData */

$div=" ";

/* Looping each $fbData['data'] */
foreach ($fbData['data'] as $fbPhotoAlbum)
/* Fetching 'id' of each album by $fbPhotoAlbum['id'], and passing that to fppg_get_photos(), and concatenating each of the generated HTML with itself and assigning it back to $div */
/* Also printing the album name by fetching it from the JSON data using $fbPhotoAlbum['name'] - Optional */
/* You can replace   as however you would like to, like for example 
  • for each album name to be in a bulleted list */ $div=$div.''.$fbPhotoAlbum['name'].'
    '; /* Removing album names of any album with the name 'Untitled Album' - Optional */ $div=str_replace('Untitled Album;','',$div); } return($div); }
  • There we go, and this is how it looks on site, here. You can find the edited source code for download here. Download the original plugin, and replace the facebook-page-photo-gallery.php with the new downloaded file after extraction. And then now, your shortcode will have to be called only once, with the page ID of the Facebook page, rather than with some album ID.

    [fbphotos id=pageid]

    That does it! :). And don’t mind coming back to your photo gallery page ever again to update or add anything. The albums will automatically update as they are fetched from the Facebook page. Just keep those albums and photos rolling on in Facebook, and see them spring up there.


    TweetBytes is now @Tweet

    @tweetbytes is now @tweet, thanks to txtWeb’s recognition of the popularity of the app amongst txtWeb users. Now that it got a snappier keyword, what does it mean for the current users? Simply put, it just got better, and easier to access. Existing users of @tweetbytes needn’t do anything to access the application through the […]

    Read More
    View the Blog »

    55444 Search for Chrome

    Got a week's break, and at least one night had to be some night of hacking. I was going through ...

    My First WordPress Plugin

    With great delight, I have contributed my first official piece of code to the WordPress repository! I was always eager to ...

    Copyright © Bits and Bytes | Arjun Abhynav. Powered by WordPress.