Yoast\WP\SEO\Values

Images::add_image_by_url()publicYoast 1.0

Adds an image based on a given URL.

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

Хуков нет.

Возвращает

number|null. Returns the found image ID if it exists. Otherwise -1. If the URL is empty we return null.

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

$Images = new Images();
$Images->add_image_by_url( $url );
$url(строка) (обязательный)
The given URL.

Код Images::add_image_by_url() Yoast 22.4

public function add_image_by_url( $url ) {
	if ( empty( $url ) ) {
		return null;
	}

	$image_id = $this->image->get_attachment_by_url( $url );

	if ( $image_id ) {
		$this->add_image_by_id( $image_id );

		return $image_id;
	}

	$this->add_image( $url );

	return -1;
}