If you have ever used RSS Feed Widgets on a website before you will know that one of the biggest aggravations is that the links always open in the same window therefore leaving your website.
I have posted numerous threads about this in the wordpress forums and haven’t really gotten a lot of response back from the community as to how I could workaround this. Here are some links to my posts:
Well, long story short, there is a workaround on this but you are going to have to get your hands dirty and mess with some code and editing the wp-includeswidgets.php file.
You will first want to go to about line #1525 in the code and insert target=’_blank’ in two locations on that file. Here’s what it will look like once you are done:
<span style="color: #606060"> 1:</span> $title = <span style="color: #006080">"<a class='rsswidget' target='_blank' href='$url' title='"</span> . attribute_escape(__(<span style="color: #006080">'Syndicate this content'</span>)) .<span style="color: #006080">"'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' target='_blank' href='$link' title='$desc'>$title</a>"</span>;
Next, you will go to approximately line #1621 and do the same thing here, adding the target=’_blank’ into the code. It will look something like this:
<span style="color: #606060"> 1:</span> echo <span style="color: #006080">"<li><a class="</span>rsswidget<span style="color: #006080">" title="</span>$desc<span style="color: #006080">" href="</span>$link<span style="color: #006080">" target="</span>_blank<span style="color: #006080">">$title</a>{$date}{$summary}$author}</li>"</span>;
Now, as with anything you do to the core wordpress software, you are going to have to make sure you add this back should you ever overwrite the software doing an upgrade, etc. Why this is not an option on the wordpress cms core functions yet is beyond me…
One way to fix the issue without editing core, would be to search for an “a href” with the class of “rsswidget” using jQuery. Then replace or add the attribute and value for target=”blank”.
This way you can update your wordpress file without worrying about any core mods. This jQuery solution could be added into the functions.php.
Thanks, next time I run into this I will check into that.
First off – thanks for this info – works great.
My only comment is I had to do it to a different file with some slightly different line locations:
wp-includes/default-widgets.php
Line 762 – add it twice withing 2 brackets – which are for the RSS title link:
$title = “<img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /> $title“;
Line 835 which addresses the link of any articles you may display:
echo “<li>$title{$date}{$summary}{$author}</li>”;
Okay, thanks for sharing. I posted this on an older version of WordPress than is out now so that might explain the line number differences.
Thanks for this, it did the trick – one mod from Sabine's comment.
Make the mods to Lines 728 and 837 on wp-includes/default-widgets.php
Modify these lines as below:
Line 728:
– –
$title = “<img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /> $title“;
– –
Line 837
– –
echo “<li>$title{$date}{$summary}{$author}</li>”;
– –
Thanks for the update.
Thank you for the widget fix
Thanks for your help :o)
Hi,
with wordpress 3.1 I had to going to 'default-widgets.php'
line 740 + 861
hope this information helps to save time for users 🙂
Awesome, thanks for the information. I had wondered how all of this related to 3.1.
Tremendous…thanks so much!
No problem. It’s surprising how popular this post continues to be.
I can’t think of one right now, but I will do some research.