How to customise WordPress RSS Feed for Flipboard

Well, if you ended up here, it most likely means two things. One, is that you are trying to make your WordPress RSS work on Flipboard. Two, is that you have visited dozens of forums and websites related to web development and still haven’t found a solution.

Here I predominantly share my Muay Thai venture and stuff related to combat sports. However, being involved in web development for quite some time, I believe I can write a few lines on this topic too.

First of all, we have indeed succeeded to get our online magazine on Flipoard, and can now share its content via RSS. This is thanks to a few people, who I will outline below.

I presume you have faced a similar situation to the following. Created an account. Created a magazine. Submitted your WordPress RSS Feed. These were some of the steps towards becoming a Publisher, right?

After submitting your RSS as a source of a magazine, the first status you saw was pending. Then it was processing. And finally… Approved? Or declined due to your WordPress RSS not meeting the required criteria as outlined on Flipboard RSS Guidelines?

Indeed, the original WordPress RSS feed is quite simple. It doesn’t really contain much. Well, it contains enough, but not enough for this particular matter.

I have contacted the Flipboard support to understand what was wrong. To mention, the customer service agent has been truly helpful, and most of all patient in dealing with a Muay Thai fighter who occasionally presses the buttons on a keyboard. Thank you to her.

The received response stated the following:

“Your feed does not contain images. The images need to be included in the enclosure node for each item in the feed.”

And the drama begins

A few (annoying) hours (days) were spent on trying to figure out how to make it work. I’ve visited a (large) number of websites, including Russian, where it is suggested to use a plugin. But we want to make it work without a plugin, right?

Then there were quite a few suggestions to put this or that code in the functions.php file. Still not working.

Sounds familiar right?

Add length and type to Wordpress RSS image enclosure

I’ve found this function posted by the user “DaveyJake” on Github. Thank you to him.

The function was added to our functions.php file. Finally, WordPress RSS contains image as an enclosure URL. But… The Length was not being featured in the outcome, which is required, along with the Type.

Not saying the function is “wrong”. But something appeared in need to be edited.

Then I’ve found one of the questions published by the user “Lee King” on Stack Overflow, titled as “How to add length and type to RSS featured image enclosure tag (WordPress)”. In fact he most likely was trying to figure out exactly the same thing.

The actual function he presented is not the one I used. But what I used was a response to him posted by the user “staypuftman”. Thank you to both of them.

The suggestion stated: “Do print_r($featured_image) and see what fields are in that array. You’ll probably find length and mime_type in there.”

This indeed provided the “id” of the length which was added into the edited function presented by “DaveyJake”. And it worked.

The Code

This code (below) I added to functions.php. The outcome saw WordPress RSS including what was needed: featured image enclosure URL with length and type.

I am not a guru when it comes to coding. I understand CSS, PHP, MySQL and all this stuff, of course. I can edit it, but I wouldn’t be coding something from zero myself and present it to others as a solution.

Always back up your database and everything else prior making any modification.

If you use the code – you use it at your own risk.

// add featured image as enclosure for Flipboard

function feedFilter($query) {
	if ($query->is_feed) {
		add_filter('rss2_item', 'feedContentFilter');
		}
	return $query;
}
add_filter('pre_get_posts','feedFilter');
 
function feedContentFilter($item) {
	
	global $post;
	
	$args = array(
		'order'          => 'ASC',
		'post_type'      => 'attachment',
		'post_parent'    => $post->ID,
		'post_mime_type' => 'image',
		'post_status'    => null,
		'numberposts'    => 1,
	);
	$attachments = get_posts($args);
	if ($attachments) {
		foreach ($attachments as $attachment) {
			$image = wp_get_attachment_image_src($attachment->ID, 'full');
			$mime = get_post_mime_type($attachment->ID);
		}
	}

	if ($image) {
		echo '<enclosure url="'.$image[0].'" length="'.$image[1].'" type="'.$mime.'"/>';
	} 
	return $item;
}

In conclusion, it can hopefully however help you achieve your goal and become a publisher on Flipboard. If it does, you can also always follow our profile and magazines, if you like combat sports.

How to

WordPress RSS Feed for Flipboard

  1. Make a backup

    First things first. Make a full backup of your website, including database.

  2. Open functions.php file

    The functions. php file is generally in your theme’s folder.

    You can open it from your WP Dashboard by clicking Appearance >> Theme Editor. It should be in the list of Theme Files on the right. Be careful when editing the file of the active theme though. Make sure if you have made a backup.

    Another way is to do it via file manager, if you have cPanel. Or you can use FTP.

  3. Add code

    Paste the code at the bottom of functions.php file.

  4. Save functions.php file

    If you have opened functions.php file via WP Dashboard or cPanel – simply click save. If you used FTP to download the file – re-uploaded it (after the code has been placed and file saved).

  5. Check

    Open in browser example.com/feed (Don’t forget to clear cache)
    Search on page for “enclosure url”.
    If you see something like <enclosure url=”https://www.example.com/wp-content/uploads/2018/12/image-file.jpg” length=”1200″ type=”image/jpeg”/> – you are done.

    This line should be appearing for each post in the feed which has a featured image.

And one more time, the actual code is not created by me, I have only edited it. So, if it works out for you, thank those who have written it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here