wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



get_url_in_content › WordPress Function

Depuis3.6.0
Dépréciéen/a
› get_url_in_content ( $content )
Paramètres:
  • (string) $content A string which might contain an `A` element with a non-empty `href` attribute.
    Requis: Oui
Retourne:
  • (string|false) Database-escaped URL via {@see esc_url()} if found, otherwise `false`.
Défini(e) dans:
Codex:

Extracts and returns the first URL from passed content.



Source

function get_url_in_content( $content ) {
	if ( empty( $content ) ) {
		return false;
	}

	$processor = new WP_HTML_Tag_Processor( $content );
	while ( $processor->next_tag( 'A' ) ) {
		$href = $processor->get_attribute( 'href' );
		if ( is_string( $href ) && '' !== $href ) {
			return sanitize_url( $href );
		}
	}

	return false;
}