888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

January 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 = '

';
$additional_content .= '

Interesting Message

';
$additional_content .= '

The content of the interesting message

';
$additional_content .= '

';

//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.

Updating Code Snippets Here
Fun plugins wordpress?
no comment
page 1338
Quick N Dirty Offline Status
How to make my offline and update database if i exit the page?
no comment
page 134
Post Image The Easy Peasy Way
How to attach image to page in wp?
26 comments
page 1065
Html 5 Gallery
Html 5 and wordpress?
6 comments
page 1305
Premium Ithemes Review Photo Gallery
Ithemes child themes?
4 comments
page 226
Html 5 Gallery
Photo gallery html5?
6 comments
page 1305
Categories Vs Tags Either Neither Or Both
Wp tags vs categories?
12 comments
page 7
Fun With Theme Widgets
Fun with theme widgets?
24 comments
page 867
Fun With Sidebar Tabs Styling
Wordpress sidebar background image?
2 comments
page 336
Wordpress Chat
Wordpress chate?
3 comments
page 1308
3 Ways To Speed Up Your Blog Without A Cache Plugin
Speed your blog?
one comment
page 1321
Quick N Dirty Replacement Text
Wpinsertpost returns 0?
no comment
page 122
My Experience Of Flexx
Flexx theme review?
4 comments
page 1026
Wordpress 25 Exif Fields
Exif wordpress?
12 comments
page 230
Pause For Thought For The Day
Pause for thought for the day?
3 comments
page 1282
Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Image url post code php?
26 comments
page 1065
Updating Code Snippets Here
Widget for wordpress fun html?
no comment
page 1338
Fun With Sidebar Tabs Styling
Wp sidebar tabs vertical?
2 comments
page 336
Updating Code Snippets Here
Rewrite specific category wordpress?
no comment
page 1338
Updating Code Snippets Here
Rewrite specific category wordpress?
no comment
page 1338
Updating Code Snippets Here
Rewrite specific category wordpress?
no comment
page 1338
Updating Code Snippets Here
Fun wordpress theme?
no comment
page 1338
Html 5 Gallery
Html 5 tabs?
6 comments
page 1305
Creating Custom Urls
Addactiontemplateredirect?
6 comments
page 80
Six Million Ways To Die Choose One
Very simply way of die?
14 comments
page 1128
Wordpress Chat
Wordpress chat?
3 comments
page 1308
Post Image The Easy Peasy Way
Wordpress show image size in posts?
26 comments
page 1065
Quick N Dirty Admin Login Screen
Loginhead?
no comment
page 128
Html 5 Gallery
Photo gallery html 5?
6 comments
page 1305
Html 5 Gallery
Wordpress html5 player plugin?
6 comments
page 1305
Why I Ditched Disqus
Intense debate turn off comments on pages?
5 comments
page 1175
Post Image The Easy Peasy Way
Cant select large image post wordpress?
26 comments
page 1065
  1 query every 1355 seconds, updated 1 seconds ago.
Post a comment?