wp_rel_nofollow_callback
Callback to add rel=nofollow string to HTML A element.
Description
(string) wp_rel_nofollow_callback( (array) $matches );
Will remove already existing rel="nofollow" and rel='nofollow' from the string to prevent from invalidating (X)HTML.
Returns (string)
HTML A Element with rel nofollow.
Parameters (1)
- 0. $matches (array)
- The matches.
Usage
if ( !function_exists( 'wp_rel_nofollow_callback' ) ) { require_once ABSPATH . WPINC . '/formatting.php'; } // The matches. $matches = array(); // NOTICE! Understand what this does before running. $result = wp_rel_nofollow_callback($matches);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/formatting.php
- function wp_rel_nofollow_callback( $matches ) {
- $text = $matches[1];
- $atts = shortcode_parse_atts( $matches[1] );
- $rel = 'nofollow';
- if ( preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'http' ) ) . ')%i', $text ) ||
- preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'https' ) ) . ')%i', $text )
- ) {
- return "<a $text>";
- }
- if ( ! empty( $atts['rel'] ) ) {
- $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
- if ( false === array_search( 'nofollow', $parts ) ) {
- $parts[] = 'nofollow';
- }
- $rel = implode( ' ', $parts );
- unset( $atts['rel'] );
- $html = '';
- foreach ( $atts as $name => $value ) {
- $html .= "{$name}=\"$value\" ";
- }
- $text = trim( $html );
- }
- return "<a $text rel=\"$rel\">";
- }