This tutorial shows how links to external sites can be set to open automatically in a new window/tab when using Oxygen.

Here’s How

Edit the Main Catch All Template.

Add a Code Block at the very end below all other top-level Sections/elements.

PHP & HTML:

<?php
	// echo "hello world!";
?>

JavaScript:

(function($) {

	$('a')
	.filter('[href^="http"], [href^="//"]')
	.not('[href*="' + window.location.host + '"]')
	.attr({
		rel: 'noreferrer noopener',
		target: '_blank'
	})

}(jQuery));

Opening all Links in a Section in new window/tab

If you wish to open all the links inside a particular element, say a Section but not all external links throughout the site, use the following JS instead inside the particular Template/Page:

jQuery('#section-178-2 a').attr({
	target: "_blank",
	rel: "noreferrer noopener"
});

Replace section-178-2 with the ID of the parent container having the links.

References

https://gist.github.com/wpscholar/4637176

https://stackoverflow.com/a/13014355/778809

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

For adding code blocks wrap the code in three backticks. Markdown should work.
Provide a URL of your site/webpage if something is not working.
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: