Site logo

Archived topic

Opening rss in new tab

3 replies · Started by Gilles on August 19, 2021

Viewing posts 1–4 of 4

Hello,
In the right sidebar of my blog (https://www.un-jardin-bio.com/blog/), I put an rss feed to my Youtube channel.
I would like the links (channel title and videos) to open in a new tab.
I don't want to use an external link plugin for this.
I would prefer to insert, at the theme level, a target = "_ blank" for rss feeds.
Is it possible ?
And if so, where?
Thank you for your help.
Regards,
Gilles

Hi there,

You can try adding the attribute through jQuery.

Example:


<script>
jQuery(document).ready(function( $ ){
  $('a.rsswidget').attr('target', '_blank');
});
</script>

Or by vanilla JS. (better)

<script>
let rss_Links = document.querySelectorAll('a.rsswidget');
for (i = 0, i > rss_Links.length; i++) {
rss_Links[i].setAttribute("target", "_blank");
}
</script>

Hook either of the 2 on the wp_footer or your site. :D

Hi Elvin
Thank you for your quick reply.
The first script works (but not the second).
Have a good day,
Gilles

No problem. Glad to be of any help. :D

This archived topic is closed to new replies.