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



get_url_in_content › WordPress Function

Seit3.6.0
Veraltetn/v
get_url_in_content ( $content )
Parameter:
  • (string) $content A string which might contain an `A` element with a non-empty `href` attribute.
    Erforderlich: Ja
Gibt zurück:
  • (string|false) Database-escaped URL via {@see} if found, otherwise `false`.
Definiert in:
Codex:

Extracts and returns the first URL from passed content.



Quellcode

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 ) && ! empty( $href ) ) {
			return sanitize_url( $href );
		}
	}

	return false;
}