WordPress at a glance

wp_targeted_link_rel() WP 1.0

Adds rel noreferrer and noopener to all HTML A elements that have a target.

✈ 1 time = 0.000249s = fast | 50000 times = 0.22s = very fast | PHP 7.2.16, WP 5.2

No Hooks.

Return

String. Converted content.

Usage

wp_targeted_link_rel( $text );
$text(string) (required)
Content that may contain HTML A elements.

Changelog

Since 5.1.0 Introduced.

Code of wp targeted link rel: wp-includes/formatting.php WP 5.2.2

<?php
function wp_targeted_link_rel( $text ) {
	// Don't run (more expensive) regex if no links with targets.
	if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a ' ) !== false ) {
		$text = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text );
	}

	return $text;
}

Related Functions

From tag: Link (tag A in HTML)

More from category: Sanitizing, Escaping

No comments
    Hello, !     Log In . Register