A couple of weeks ago we were looking into how to modify the feed on Blogging Tips to include the author’s URL in with their post. There are plenty of plugins that allow you to add additional comments to the end or beginning of the content, but no obvious way to edit the author line that appears under the post title.
Most bloggers on a multi author blog often have their own individual blog, so being able to not just credit them but also provide a link direct to their site from the feed is a great way to give more exposure to the blogger.
So first of all we need to know the correct template tag to use to get the author’s website link. This is the link provided in their profile. To get the direct link we can use
<?php the_author_url() ?>
Next we need to edit the appropriate core file (for this example I’ll be using the RSS 2.0 file). The only downside to this is that when WordPress upgrades you’ll have to edit the file again (I will continue to search and see if there’s a way to do this via a plugin). The file we need to edit can be found under wp-includes/feed-rss2.php.
If you open this file up and navigate to about line 40 you should see the following code:
<dc:creator><?php the_author() ?></dc:creator>
We need to simply edit this to include the author’s site link i.e.
<dc:creator><?php the_author() ?> from <?php the_author_url() ?></dc:creator>
You can see this in action on the Blogging Tips Feed.
The only problem here is that maybe not every blogger will have a website link in their profile. We don’t really want it to appear as
“By Sarah from “
As it looks a bit unprofessional. So instead we need to check that the author has added a link to their profile, and if they have then we can add it. We use a simple if statement for this along with the tag get_the_author_url() as this will return a url rather than just printing it out on screen. To do this we use
<?php
$authorurl = get_the_author_url();
if (!empty($authorurl)) :
echo "from ".$authorurl;
endif;
?>
The above assigned the value of the get_the_author_url() function to the variable $authorurl. Then it checks to see if the $authorurl has a value, if it does then it will proceed with the if statement and echo out the ‘from sitelink’, otherwise it continues without adding anything. So to add this all together we now have
<dc:creator><?php the_author();
$authorurl = get_the_author_url();
if (!empty($authorurl)) :
echo " from ".$authorurl;
endif;
?></dc>
This will now give you either
“by Sarah”
for authors without a site link, or
“by Sarah from http://www.stuffbysarah.net”
for authors with a site link.
You may wonder why I’ve only covered the RSS 2.0 feed. Atom has this built in by default, and the RSS 0.92 file doesn’t have an author element. You could however add this to before or after the content.
Author comments are in a darker gray color for you to easily identify the posts author in the comments
Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums
Hey! Great tip. I run a multi-author blog and will use this
I don’t think much bloggers use that “authors” function on Wordpress anymore. Most just have a small excerpt to the guest poster, which definitely shows up in the feed.
-Mike
good information! i’ll use this on my next blogging project.. there will be two bloggers who will write for our upcoming blogging project..
Cool feature, I never knew about this
@Mike Huang – for guest blogging that’s fine, but plenty of sites also have multiple authors with WordPress logins and profiles such as Blogging Tips, and this idea/option is targeted to those sites
Very helpful guide Sarah. I’m sure a lot of people will find this helpful
Cheers Kevin. If I can work out how to put this into a plugin (it’s a bit different to just editing your content) then I’ll post up about that too!