logo
  • Home
  • About
  • Plugins

Subscribe to Articles

Quick n’ Dirty Feed Footers

Author: andrew Category: Uncategorized Tags: plugins, Snippets

Sunday
Jan 27, 2008

Quick N Dirty

This is the fourth of my Quick N Dirty plugin posts. In the first I used the the_content filter to repeat the links used in a post, at the end of that post. In this post I am going to the_content again, but this time I am specifically using it in place of another filter that could get you quite confused.

It is a pretty common thing to do these days, add a footer to each post in your feed. There are a few plugins that not only let you do it but give you a handy admin page to alter the content as well. Nothing beats knowing how to do it yourself though.

If you are going to do it yourself, there is one area that provides some confusion. There is a filter that sounds like it should be used, but simply won’t work for you. That filter is the_content_rss.

The problem is that the_content_rss is used in rss, and rdf feeds, but importantly not in the rss2 feeds which is what we all tend to use these days. So if you want to change the content of your feeds, for the moment at least, you need to use the_content and check to see whether a feed is being requested. Luckily this is very easy.

Here’s the plugin:

<?php
/*
Plugin Name: Quick n' Dirty Feed Footers
Plugin URI: http://www.wp-fun.co.uk/2008/01/27/quick-n-dirty-feed-footers/
Description: Adds content to the bottom of each rss2 post
Author: Andrew Rickmann
Version: 1
Author URI: http://www.wp-fun.co.uk
*/
 
//This is the line that adds your filter into the list.
// 'the_content' is the name of the filter
// 'qnd_feed_content' is the name of the function, below
add_filter( 'the_content' , 'qnd_feed_content' );
 
function qnd_feed_content( $content ){
 
//make sure that a feed is being requested
if ( is_feed() ) {
 
	//create a string containing the html we want to add to the bottom
	$additional_content = '<div style="border:1px solid #ccc; padding:5px; background-color:#DBD2DC">';
	$additional_content .= '<h2 style="margin:0 0 5px 0; font-size:95%; color:#AC26A7">Interesting Message</h2>';
	$additional_content .= '<p>The content of the interesting message</p>';
	$additional_content .= '</div>';
 
	//return the content, and the additional content to WordPress
	return $content . $additional_content;
} else {
	//if we are not within a feed just send back the original content
	return $content;
}
}
 
?>

I have used a basic WordPress tag - is_feed() - to check if a feed is being accessed. Once known the content can be modified. Very important, as with previous plugins is to return the content without changes if it is not a feed. As this is a filter, if no content is returned then no content will be displayed on screen.

Note: If you copy the content of this plugin you will need to replace all the quote marks as WordPress replaces them with fancy ones.


Share:
image image image image image

Comments are closed.

Quick n’ Dirty Post Exclusion
Suck My Knee Muddy Funkster

Recommended

wordpress unlimited

Archives

  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007

Tags

2.7 2.8 Admin Advertising Air Blogging blogs Cache Cliche Coding Comments Content Types CSS Curry Death development Disqus Features Habari image Interview Licensing Modes Monday Poll New Features Organisation Personal Platform Plugin Plugin-Practices plugins Plugin update Poll premium Readers Reviews Search Simplification Snippets Spam Themery Themes tools User Interface Widgets WLTC

Copyright 2009 Fun with WordPress - All Rights reserved.

Wordpress theme by: WPUnlimited