# A link that opens in a new tab, safely

> A link field printed with the right target and rel attributes.

Source: https://uglydev.com/recipes/a-link-that-opens-in-a-new-tab-safely/
Updated: 19 November 2026

```php
<?php $link = ugly_get( 'link' ); ?>
<?php if ( $link ) : ?>
	<a href="<?php echo esc_url( $link['url'] ); ?>"
		<?php echo '_blank' === $link['target'] ? 'target="_blank" rel="noopener noreferrer"' : ''; ?>>
		<?php echo esc_html( $link['title'] ); ?>
	</a>
<?php endif; ?>
```
