Set Microsoft Word links to open in new window/tab

I'm unable to set Word hyperlinks to open in a new window/tab. Basically, I create a Word document and paste its contents to WordPress, and everything is there, links do work, but they don't have "target=_blank" attribute added to them.

I do set Target Frame option in Word, but nothing happens. I've tried using _blank and New Window values, but when looking at code the target attribute isn't added.

I tried using Ctrl + F9 trick to force my links to open in new window, but that doesn't work.

Is there a way to fix that?

EDIT: This is a Word-related issue. I'm not developing a WordPress theme, I just want to paste the text from Word into WordPress and have my links open in new window. This works perfectly with Libre Office, but not with Microsoft Office.

Topic the-content filters Wordpress

Category Web


The solution for this would be to build a filter on the_content that scans the pasted text for links and adds target="_blank". Actually, you don't even have to build it yourself, because WP has a built in function to do this. All you have to do is add this line to the functions.php of your theme:

add_filter ('the_content','links_add_target');

Beware that if your theme is updated your functions.php will be replaced and your edit lost. The correct way to circumvent this would be to build a child theme.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.