Open All Links in New Windows, WordPress add target blank in all a html elements

 In Admin, All, Themes

Open All Links in New Windows, WordPress add target blank in all


html elements.

I am personally not a fan of opening links in new windows – I think it should be left for the user to decide, as I explained in this post. But I’m not one to judge, so if you want to do it, use this simple code snippet on your WordPress theme’s functions.php file.

WordPress code snippet:

function ns_autoblank($text) {
	$return = str_replace('<a', '<a target="_blank"', $text);
	return $return;
add_filter('the_content', 'ns_autoblank');


Find out more about functions here

Thank you for seeing my tutorial and fell free to share and comment 🙂 . Do you have a code snippet and you want to see it publish on my site ? I will be more than happy to do it please send me a message (here)

Recommended Posts

Start typing and press Enter to search

Let's work together

I'd love to work with you! Please fill out my project form to tell me more about your project/work. I reply to all enquiries within 48 hours.


  • January - Available
  • February - Available
  • March - Available


  • My day rate is £300.
  • I can provide a fixed price for your work.

EN - Header Enquiry Form

  • This form collects your name, email address and telephone number so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.