WPSEO_Sitemaps_Renderer::sitemap_url()publicYoast 1.0

Build the <url> tag for a given URL.

Public access for backwards compatibility reasons.

Метод класса: WPSEO_Sitemaps_Renderer{}

Хуки из метода

Возвращает

Строку.

Использование

$WPSEO_Sitemaps_Renderer = new WPSEO_Sitemaps_Renderer();
$WPSEO_Sitemaps_Renderer->sitemap_url( $url );
$url(array) (обязательный)
Array of parts that make up this entry.

Код WPSEO_Sitemaps_Renderer::sitemap_url() Yoast 22.4

public function sitemap_url( $url ) {

	$date = null;

	if ( ! empty( $url['mod'] ) ) {
		// Create a DateTime object date in the correct timezone.
		$date = YoastSEO()->helpers->date->format( $url['mod'] );
	}

	$output  = "\t<url>\n";
	$output .= "\t\t<loc>" . $this->encode_and_escape( $url['loc'] ) . "</loc>\n";
	$output .= empty( $date ) ? '' : "\t\t<lastmod>" . htmlspecialchars( $date, ENT_COMPAT, $this->output_charset, false ) . "</lastmod>\n";

	if ( empty( $url['images'] ) ) {
		$url['images'] = [];
	}

	foreach ( $url['images'] as $img ) {

		if ( empty( $img['src'] ) ) {
			continue;
		}

		$output .= "\t\t<image:image>\n";
		$output .= "\t\t\t<image:loc>" . $this->encode_and_escape( $img['src'] ) . "</image:loc>\n";
		$output .= "\t\t</image:image>\n";
	}
	unset( $img );

	$output .= "\t</url>\n";

	/**
	 * Filters the output for the sitemap URL tag.
	 *
	 * @param string $output The output for the sitemap url tag.
	 * @param array  $url    The sitemap URL array on which the output is based.
	 */
	return apply_filters( 'wpseo_sitemap_url', $output, $url );
}