I recently read Darek Kay's excellent post about styling RSS feeds and wanted to do something similar.
So, here's my simple guide to styling your WordPress blog's RSS / Atom theme. The end result is that if someone clicks on a link to your feed, they see something nicely formatted, like this:
Prerequisites
This involves editing your WordPress blog's theme. If you don't know what you're doing, you can mess up your blog0. Make sure you take some backups before experimenting on your live site.
Download an XSLT
You can download my Style Sheet which I stole from Darek's website and then enhanced. Save it as rss-style.xsl in your theme's root directory.
Edit it in a regular text editor to have the name of your blog.
Create a new Atom Feed Template
WordPress has a bunch of built in feed templates.
Copy the file /wp-includes/feed-atom.php and paste it into your theme's root directory. Rename it custom-feed-atom.php
There are three lines which need editing.
Near the top you should see
PHP
header( 'Content-Type: ' . feed_content_type( 'atom' ) . '; charset=' . get_option( 'blog_charset' ), true );
The feed_content_type needs to be set to rss-http - otherwise most modern browsers will try to download the Atom feed rather than display it. The new line should be:
PHP
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
After that, add the line:
PHP
$theme = $args["theme"];
That will allow us to get the theme directory.
Finally, find the line:
PHP
echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
Immediately after that, add the line:
PHP
echo '<?xml-stylesheet href="' . $theme . '/rss-style.xsl" type="text/xsl"?>';
That allows the browser to see the stylesheet you saved earlier.
Functions
Finally, it is time to edit your theme's functions.php file. This will remove the old Atom feed and add your new one.
I don't know how your functions.php file is set up. But, generally speaking, you can safely add these lines to the very end of it:
PHP
function my_custom_atom() { get_template_part( 'custom-feed', 'atom', array( "theme" => get_stylesheet_directory_uri() ) ); } remove_all_actions( 'do_feed_atom' ); add_action( 'do_feed_atom', 'my_custom_atom', 10, 1 );
That removes your old Atom feed, and calls the new template that you saved earlier, and passes it the URl for your CSS.
Done!
You can see what it looks like at https://shkspr.mobi/blog/feed/atom/
Nice!
-
TBF, you can mess up even if you do know what you are doing. ↩︎

8 thoughts on “Style your WordPress Atom feed”
@Edent Nice 🙂 On FixMyStreet we use the same templates for HTML emails to style it, which makes it nice and maintainable: https://www.fixmystreet.com/rss/pc/B24QA
XSL is https://github.com/mysociety/fixmystreet/blob/master/templates/email/default/xsl.xsl
| Reply to original comment on mastodon.social
@Edent such a good idea (that I still haven’t gotten around to implementing myself!)
always admired @davatron5000’s styled feed: https://daverupert.com/atom.xml
| Reply to original comment on mastodon.social
anonymous
I've been adding bonus features to my blog's RSS feeds for a while now. Wanna hear about them?
| Reply to original comment on danq.me
@edent
Yes please!
@Edent I did this for my feeds! XSLT is fun 🙂
https://balintmagyar.com/articles.xml
https://balintmagyar.com/posts.xml
| Reply to original comment on mastodon.social
@Edent That's a brilliant idea. I never thought about it. This one guy 7 years from now should appreciate it*.
*It's not sarcasm. I really think the only reason to do it is because I can and because it would be fun.
| Reply to original comment on mstdn.social
@blog WordPress already use XSLT for the sitemap e.g. https://shkspr.mobi/blog/wp-sitemap.xml
Maybe the should standardise for other xml-formats WP produces?
| Reply to original comment on mastodon.social
@blog WordPress already use XSLT for the sitemap e.g. https://shkspr.mobi/blog/wp-sitemap.xml
Maybe WP should standardise on a xlst for other xml-formats it produces?
| Reply to original comment on mastodon.social
More comments on Mastodon.
What links here from around this blog?