wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_rel_callback › WordPress Function

Seit5.3.0
Veraltetn/v
wp_rel_callback ( $matches, $rel )
Parameter: (2)
  • (array) $matches Single match.
    Erforderlich: Ja
  • (string) $rel The rel attribute to add.
    Erforderlich: Ja
Gibt zurück:
  • (string) HTML A element with the added rel attribute.
Definiert in:
Codex:

Callback to add a rel attribute to HTML A element.

Will remove already existing string before adding to prevent invalidating (X)HTML.


Quellcode

function wp_rel_callback( $matches, $rel ) {
	$text = $matches[1];
	$atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );

	if ( ! empty( $atts['href'] ) && wp_is_internal_link( $atts['href']['value'] ) ) {
		$rel = trim( str_replace( 'nofollow', '', $rel ) );
	}

	if ( ! empty( $atts['rel'] ) ) {
		$parts     = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
		$rel_array = array_map( 'trim', explode( ' ', $rel ) );
		$parts     = array_unique( array_merge( $parts, $rel_array ) );
		$rel       = implode( ' ', $parts );
		unset( $atts['rel'] );

		$html = '';
		foreach ( $atts as $name => $value ) {
			if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
				$html .= $name . ' ';
			} else {
				$html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
			}
		}
		$text = trim( $html );
	}

	$rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';

	return "<a {$text}{$rel_attr}>";
}