Archived topic
How to change from open in new window to same window
1 reply · Started by Anton on November 4, 2020
Hi there,
Didn't see an answer to this via search. On my site, I set almost all links (internal and external) to open in a new tab (window). I'd now like to have all internal links open in the same tab, with external links opening in a new tab.
Or, if it's simpler, just have all links open in the same tab.
Is there a way to reliably do this across the board with some Javascript, or otherwise?
Many thanks (love this theme!!).
Hi there,
you could try filtering the content with preg_replace to remove the Target attribute:
add_filter('the_content', 'db_remove_target_blank_in_content', 15);
function db_remove_target_blank_in_content($content)
{
return preg_replace('#target=["\']?_blank["\']?#mi','',$content);
}
I would suggest testing this on a staging site in case it creates any unintentional side effects.