Articles Comments

Marco Luthe Online! » WordPress Stuff » Incomplete Feeds When Using Post Pagination

Incomplete Feeds When Using Post Pagination

Recently, I discovered the beautiful <!–nextpage–> tag with which you can split your posts into two or more pages (see the WordPress Codex for more information on this). Since some posts in my Migrating To Australia Diary were a little long for just one page, this tag came in pretty handy.

After implementing this tag into one of the posts (which worked fine), I realized that the RSS feed of my blog now only showed the first page of that multipage post, without any comment or hint that only one page was shown to the readers of the feed. This is certainly not the way it should be, because that way, some readers might miss out on things if they only read the feed.

I posted this problem on the official WordPress support forum, but got no answer so far. So, I also tried the German WordPress forum, and a guy called Maxe came up with a nice link only two ours after my post that solved the problem.

The solution is quite simple:
Hook into the filter the_content and check if a feed is requested or not. If it is not a feed, then just return what the function get_the_content() has produced (which might be one of multiple post pages, if you used the <!–nextpage–> tag). If it is a feed, though, replace what might just be the content of one page of the post with the whole original post content from the database. That’s it!

You see: without this plugin, only one page of the post is shown by the function get_the_content() , since that function doesn’t actually make a difference between a post and a feed. The difference is that – provided you use wp_link_pages() in your theme – the different pages numbers will be visible to the reader. In the feed, they are simply missing.

Since I think it is hard to find the actual link for the solution, I take the liberty of reproducing the original source code here. If there are any objections to this, please let me know.

There are 5 easy steps to get “Full Text Feeds”:

  1. Copy the code below into a blank text file.
  2. Save the file as “Full Text Feeds.php”.
  3. Upload the file into your plugins folder (/wp-content/plugins/).
  4. Got to your WordPress dashboard (/wp-amin/) and choose “Plugins”.
  5. Activate the “Full Text Feeds” plugin – done!

From now on, your feeds should always show the whole contents.

And here is the code with all the credits. Unfortunately, the Plugin URI leads to a file-not-found error, which is also a reason why I post the source code here – I couldn’t find anything about this on Simon’s website (@Simon: if you can provide a working link, I’ll put it here).

<?php
/*
Plugin Name: Full Text Feeds
Plugin URI: http://simonwheatley.co.uk/wordpress/full-text-feeds
Description: Fixes a bug in WP's feeds whereby they are only served with the first page.
Version: 1.1
Author: Simon Wheatley
Author URI: http://simonwheatley.co.uk/
*/

function ftf_full_text_for_feeds( $content ) {
if ( ! is_feed() )
return $content;
global $post;
$content = $post->post_content;
return $content;
}

add_filter( 'the_content', 'ftf_full_text_for_feeds', -100 );

?>
<?php
/*
Plugin Name: Full Text Feeds
Plugin URI: http://simonwheatley.co.uk/wordpress/full-text-feeds
Description: Fixes a bug in WP's feeds whereby they are only served with the first page.
Version: 1.1
Author: Simon Wheatley
Author URI: http://simonwheatley.co.uk/
*/

function ftf_full_text_for_feeds( $content ) {
	if ( ! is_feed() )
		return $content;
	global $post;
	$content = $post->post_content;
	return $content;
}

add_filter( 'the_content', 'ftf_full_text_for_feeds', -100 );

?>

Filed under: WordPress Stuff · Tags: , , , , , ,

blog comments powered by Disqus