Zit Seng's Blog

A Singaporean's technology and lifestyle blog

Fixing Instant Articles for WP

Of late, I’ve been struggling to fix an annoying anomaly on my blog. I had noticed that posts shared from my blog to Facebook were showing with the wrong post details. Instead of showing the specific title and content excerpt of the post, Facebook was showing generic information about the blog site itself.

Some initial troubleshooting with the Open Group Debugger revealed that Facebook had somehow failed to retrieve the correct Open Graph properties of the post. In fact, the debugger says that my blog website had generated a HTTP 404 status when Facebook attempted to scrape for information.

Without getting too long-winded, it turned out that the Instant Articles for WP plugin was somehow telling Facebook about a new post, as soon as I’ve only just begun writing it, and certainly way before it’s been saved, let alone published. This causes Facebook to poll my blog for the post, which isn’t yet published, thus getting a not found error, and populating Facebook’s cache with generic blog information.

When the post does eventually get published, Facebook relies on its incorrect cached information instead of polling again for Open Graph properties.

Posting on the plugin support forum somehow did not elicit any response. I suppose other people who used Instant Articles weren’t bothered by the error, hadn’t noticed the error, or somehow don’t separately share their posts on Facebook.

Thank goodness for open source. More specifically, that source code was available. I suppose it has to be, since this is all written in PHP anyway. So if something really annoys me enough, I could fix it myself.

That’s what I did.

diff -uNr /tmp/fb-instant-articles/meta-box/class-instant-articles-meta-box.php fb-instant-articles/meta-box/class-instant-articles-meta-box.php
--- /tmp/fb-instant-articles/meta-box/class-instant-articles-meta-box.php	2016-04-14 23:30:56.000000000 -0400
+++ fb-instant-articles/meta-box/class-instant-articles-meta-box.php	2016-06-11 22:47:35.470375148 -0400
@@ -67,6 +67,7 @@
 		Instant_Articles_Settings::menu_items();
 		$settings_page_href = Instant_Articles_Settings::get_href_to_settings_page();
 
+		if ($published) {
 		try {
 			$fb_app_settings = Instant_Articles_Option_FB_App::get_option_decoded();
 			$fb_page_settings = Instant_Articles_Option_FB_Page::get_option_decoded();
@@ -90,6 +91,7 @@
 		} catch ( FacebookResponseException $e ) {
 			$submission_status = null;
 		}
+		}
 
 		include( dirname( __FILE__ ) . '/meta-box-template.php' );
 

Yes, it was just a really minor fix. But it was really frustrating. It wasn’t obvious that the problem was with the Instant Articles for WP plugin because, well, the anomaly started occurring without any changes to the plugin. In fact, the anomaly seemed to have started without any software updates on WordPress at all. My guess is that some changes with the Facebook API must have happened to trigger this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

View Comment Policy