Support » Plugins and Hacks » [Resolved] Creating a custom RSS feed

[Resolved] Creating a custom RSS feed

  • Hi !

    I need to have a rss feed for a partner that includes an image for each post.
    I started by developping a plugin that adds an enclosure to each item with the image.
    Unfortunately my partner doesn’t get it. He gave me an example feed which contain HTML in the decription… what a shame.
    Unfortunately it’s the only way to get the images to them.
    So I’m wondering how to do that…
    Create a new feed especially for that purpose seems like the best solution. But where should I add an action to build that feed ? Which action triggers the RSS feed generation ?

    Thanks for your help or for any ideas on how to work around the problem.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Samuel Wood (Otto)


    WordPress.org Tech Dude

    In a plugin:

    1. Create a function to produce your feed’s output. You can either load a template to produce it or just produce the output directly. Either way, you’ll have the full Loop capabilities and everything else, just like any other template.

    2. Call add_feed($feedname, $function) to add the feed type.

    3. Then you can access the feed like any other.


    function feed_fake($comment) {...do stuff...}
    add_feed('fake', 'feed_fake');

    Resulting URL:
    http://example.com/blog/feed/fake/ or
    …depending on your permalinks, of course.

    Note that the function will receive one parameter. This will be true if the user is requesting a comment feed (a feed from the single post pages which contain all the reader comments). You can ignore it or not. Your call.

    Thanks a lot for the quick answer, I’ll try that right now !
    Didn’t know about the add_feed function.

    I’m getting an error when trying that.

    Here is my plugin code:

    function feed_infosjeunes() {
    	// echo 'test';

    and here is the error i get:
    Warning: in_array(): Wrong datatype for second argument in /Applications/MAMP/htdocs/styleandthecity/street-style-paris-fashion-week/wp-includes/rewrite.php on line 30

    Warning: Cannot modify header information – headers already sent by (output started at /Applications/MAMP/htdocs/styleandthecity/street-style-paris-fashion-week/wp-includes/rewrite.php:30) in …

    Moderator Samuel Wood (Otto)


    WordPress.org Tech Dude

    Ahh. I see the problem. It’s trying to alter the rewrite rules before the rewrite stuff has been loaded up.

    Try waiting until the ‘init’ hook is called before calling the add_feed function.

    function add_my_feed() {

    Works like a charm ! Tanks again for the valuable help. You saved me a few hours and an headache.

    I also needed to create custom feeds and this post came quite in handy.

    I just added a plugin that might be relevant to those tackling the same problem, which might make custom feed creation a bit easier:

    I tried the code in this post and the Feed Wrangler plugin, but didn’t seem to get what I needed.
    If any of you have any insight into my problem, posted at http://wordpress.org/support/topic/169262 please let me know!


    Found the answer here http://wordpress.org/support/topic/170995


    Thank you Otto – just the job!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Creating a custom RSS feed’ is closed to new replies.