Scripts and Style wrote a short post about adding a custom XML tag to your Atom feed. Unfortunately, they took the wrong route, and decided to change feed-atom.php, the file that serves up the Atom feed for a blog.
This is not at ALL necessary. The right way of doing stuff like this is writing a plugin that takes care of it, so nothing breaks when you upgrade. If you look a bit further down the code of feed-atom.php, you’ll see this line of code:
<?php do_action('atom_entry'); ?>
This line of code shows that there’s a so called “hook” to which you can attach an action. You attach an action to this particular hook by writing the following code:
add_action('atom_entry','add_directurl');
The first variable is the hook, the second is the function you want to call to perform your desired action. The desired action in this case was adding this line of code:
<directurl><?php echo get_post_meta($post->ID,'Author Webpage',1); ?></directurl>
So we have to write a small function that does this:
function add_directurl() {
echo '<directurl>';
echo get_post_meta($post->ID,'Author Webpage',1);
echo '</directurl>';
}
Of course that could be a one liner too but that wouldn’t be readable here. Now we wrap those two small blocks of code together, and add the default plugin “head” to it, and we’ve got ourselves a new plugin:
<?php
/*
Plugin Name: Add Direct URL to Atom Feed
Version: 0.1
Plugin URI: http://yoast.com/wordpress/
Description: Adding custom "DirectURL" tag to Atom feeds.
Author: Joost de Valk
Author URI: http://yoast.com/
*/
function add_directurl() {
echo '<directurl>';
echo get_post_meta($post->ID,'Author Webpage',1);
echo '</directurl>';
}
add_action('atom_entry','add_directurl',10,1);
?>
Now, when you upgrade, you won’t have to change anything, and you can safely assume that everything will keep working!



Or you can use functions.php file without writing a plugin. It’s right?
fatihturan,
I don’t do much customization of WP so I could be wrong but if you used a plugin it would be easier to share with other, meaning easier for non coders to implement.
Also I’m not sure which functions.php you are referring to, WP or the theme, but if WP or your theme were upgraded you would probably lose those changes.
@fatihturan: right, but this one’s more portable, as justin rightly points out!
Hi Joost,
Great information as always. That clears things up quite a bit, and I think I’ll tackle a few little code tweaks I’ve been procrastinating about for awhile. You’ve got a great blog, and you provide an awesome service to the WordPress community at large, thanks and keep up the great work! We use a number of your plug-ins on our blog.
Christopher Rees
Palaestra Training
Joost, you’re the fucking man, man! I have been trying to get my feet wet in the pool of WP plugins, and this post couldn’t be more timely for me to realize I just need to write a few small ones to get the hang of it.
Fantastic! How is that i’ve not seen such a simple explanation before? Many thanks, Joost!
Thanks Yoast,
As a WP newbie I constantly refer to your site. A bit ago I added “learn basics of WP plugins” to my long “to do” list. I think you just gave me the start I needed. Off the top of your head are there any other posts you’ve written or come across?
Cheers, and thanks again…