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.

Post Image The Easy Peasy Way
Get post attacments?
26 comments
page 1065
Upload From Url
Upload to url?
6 comments
page 326
Are Child Themes The Best Option
Wp child themes?
15 comments
page 1262
Silence Is Golden
Silence is golden wordpress?
3 comments
page 213
How To Add Sidebars To A Theme
Html hot add a side bar?
11 comments
page 1053
Fun With Sidebar Tabs Styling
Position of the tabs thematic?
2 comments
page 336
How To Add Sidebars To A Theme
How to add picture to the wordpress sidebar on sidebarphp?
11 comments
page 1053
Using Your Own Url Shortener
Short url?
4 comments
page 1190
Why I Ditched Disqus
Styling disqus widgets?
5 comments
page 1175
Wordpress 25 Exif Fields
Wordpress exif?
12 comments
page 230
Html 5 Gallery
Html 5 gallery?
6 comments
page 1305
Dont Mess With My Toot Toot
Fun with toots?
16 comments
page 599
Dont Mess With My Toot Toot
Fun with toots?
16 comments
page 599
Converting Wordpress Themes To Habari
Habari timthumb?
one comment
page 694
Wordpress 25 Exif Fields
Habari timthumb?
12 comments
page 230
Fun With Sidebar Tabs Styling
Tabs with html css on same page javascript?
2 comments
page 336
Using Your Own Url Shortener
How to have own url short?
4 comments
page 1190
Post Image The Easy Peasy Way
Insert conditional image php wp?
26 comments
page 1065
How To Add Sidebars To A Theme
Wordpress sidebar above main sidebars?
11 comments
page 1053
Using Your Own Url Shortener
Run short url using htaccess?
4 comments
page 1190
Html 5 Gallery
Html5 simple wordpress theme?
6 comments
page 1305
Dont Mess With My Toot Toot
New posttype not displayed wordpress?
16 comments
page 599
Quick N Dirty Replacement Text
Wpupdatepost object?
no comment
page 122
Updating Code Snippets Here
Fun wordpress plugin?
one comment
page 1338
How To Add Sidebars To A Theme
Wp register sidebars?
11 comments
page 1053
Html 5 Gallery
Html5 wordpress theme?
6 comments
page 1305
Post Image The Easy Peasy Way
Get post images?
26 comments
page 1065
Updating Code Snippets Here
Wordpress fun plugins?
one comment
page 1338
Post Image The Easy Peasy Way
Wordpress get first image large?
26 comments
page 1065
Using Wordpress As A Php Framework
Wordpress create your own framework?
2 comments
page 335
Improve Your Typography With Plugins
Wordpress typography plugin?
one comment
page 721
Quick N Dirty Replacement Text
Dirty replacement?
no comment
page 122
How To Add Sidebars To A Theme
How to add pages in footer wordpress?
11 comments
page 1053
  1 query every 1911 seconds, updated 1 seconds ago.
Post a comment?