_make_clickable_rel_attr()
Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable().
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
Hooks from the function
Return
String
. The rel attribute for the anchor or an empty string if no rel attribute should be added.
Usage
_make_clickable_rel_attr( $url );
- $url(string) (required)
- The URL.
Changelog
Since 6.2.0 | Introduced. |
_make_clickable_rel_attr() make clickable rel attr code WP 6.8
function _make_clickable_rel_attr( $url ) { $rel_parts = array(); $scheme = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) ); $nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) ); // Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed). if ( ! wp_is_internal_link( $url ) && in_array( $scheme, $nofollow_schemes, true ) ) { $rel_parts[] = 'nofollow'; } // Apply "ugc" when in comment context. if ( 'comment_text' === current_filter() ) { $rel_parts[] = 'ugc'; } $rel = implode( ' ', $rel_parts ); /** * Filters the rel value that is added to URL matches converted to links. * * @since 5.3.0 * * @param string $rel The rel value. * @param string $url The matched URL being converted to a link tag. */ $rel = apply_filters( 'make_clickable_rel', $rel, $url ); $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : ''; return $rel_attr; }