WordPress RSS Widget: Open Links in a New Window

Home/WordPress RSS Widget: Open Links in a New Window

I’ve recently come across a slight problem with one of my clients whereby they wanted the RSS feed widget to open all incoming links in a new window. And why wouldn’t they? Especially if they’re external RSS feeds that are being parsed.

We could have used the Better RSS plugin, but until I knew that I had to poke around and see whether it was possible. Of course it was. Here’s what you need to do.

Open WordPress RSS Feed using an additional target=”_blank” command

Find around line 898 of defaults-widgets.php in your wp-includes folder.

Replace:

if ( $link == '' ) {
echo "

  • $title{$date}{$summary}{$author}
  • ";
    } else {
    echo "

  • $title{$date}{$summary}{$author}
  • ";
    }

    With:

    if ( $link == '' ) {
    echo "

  • $title{$date}{$summary}{$author}
  • ";
    } else {
    echo "

  • $title{$date}{$summary}{$author}
  • ";
    }

    And you’re done! Of course, future WordPress updates could break this so it might be best to either create a function or use an alternative, but I thought I’d add it just for reference.

    2017-05-19T15:48:06+00:00 June 4th, 2013|PHP Snippets, WordPress Snippets|1 Comment

    About the Author:

    Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

    One Comment

    1. John Peterson September 20, 2013 at 8:11 pm - Reply

      Warren’s article and suggestion worked! Fast and easy, the way it should be! Problem is, most people had a very long and drawn out explanation on how to open a new window with an RSS Feed in WordPress?.It would be great if most people even knew how to write an article or post, let alone explaining how to do something!
      Thank you Warren!!

    Leave A Comment