PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Credit your Authors in your Feed

Posted by on 9th Nov 2008 WordPress Coding & Design 7 comments

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.

Select the Feed File

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.

Authors without a Link?

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.

Other Feeds

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.

A PHP Developer using WordPress to power both blogging and commercial CMS sites. I've written and released a couple of plugins for WordPress and am currently writing plugins for use on commercial websites.

7 comments - Leave a reply
  • Posted by Farrhad on 9th Nov 2008

    Hey! Great tip. I run a multi-author blog and will use this :)

  • Posted by Mike Huang on 9th Nov 2008

    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

  • Posted by daiLyFeed on 9th Nov 2008

    good information! i'll use this on my next blogging project.. there will be two bloggers who will write for our upcoming blogging project..

  • Posted by Sarah on 9th Nov 2008

    @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 :)

  • Posted by Affiliate marketing guide on 10th Nov 2008

    Cool feature, I never knew about this :)

  • Posted by Kevin Muldoon on 10th Nov 2008

    Very helpful guide Sarah. I'm sure a lot of people will find this helpful :)

  • Posted by Sarah on 10th Nov 2008

    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!