acf_field_link::format_value_for_jsonld
Formats the field value for JSON-LD output.
Метод класса: acf_field_link{}
Хуков нет.
Возвращает
mixed.
Использование
$acf_field_link = new acf_field_link(); $acf_field_link->format_value_for_jsonld( $value, $post_id, $field );
- $value(разное) (обязательный)
- The value of the field.
- $post_id(int|строка) (обязательный)
- The ID of the post.
- $field(массив) (обязательный)
- The field array.
Список изменений
| С версии 6.8.0 | Введена. |
Код acf_field_link::format_value_for_jsonld() acf field link::format value for jsonld ACF 6.8.8
public function format_value_for_jsonld( $value, $post_id, $field ) {
if ( empty( $value ) ) {
return null;
}
// Get link data.
$link = $this->get_link( $value );
if ( empty( $link['url'] ) ) {
return null;
}
// Get output format with fallback.
$output_format = $field['schema_output_format'] ?? '';
if ( empty( $output_format ) ) {
$property = $field['schema_property'] ?? '';
$output_format = \ACF\AI\GEO\Schema::get_default_output_format( $this->name, $property );
}
// Default to URL if no format determined.
if ( empty( $output_format ) ) {
$output_format = 'URL';
}
// URL format - just return the URL string.
if ( 'URL' === $output_format ) {
return $link['url'];
}
// WebPage format - return structured object.
$webpage = array(
'@type' => 'WebPage',
'url' => $link['url'],
);
// Add title as name if available.
if ( ! empty( $link['title'] ) ) {
$webpage['name'] = $link['title'];
}
return $webpage;
}