Skip to content

Instantly share code, notes, and snippets.

@mihdan
Created July 10, 2023 09:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mihdan/04f6a0c5b263d847574fa55d5da28e46 to your computer and use it in GitHub Desktop.
Save mihdan/04f6a0c5b263d847574fa55d5da28e46 to your computer and use it in GitHub Desktop.
Расширяет микроразметку BlogPosting в плагине WP Schema Pro для получения контентной аналитики (дочитываемость, категории, автора, тематики) в Яндекс.Метрике
<?php
add_filter(
'wp_schema_pro_schema_article',
/**
* Расширяет микроразметку BlogPosting для Яндекс.Метрики.
*
* @link https://metrika.yandex.ru/support/metrica/publishers/schema-org/json-ld.html#json-ld__identifier-desc
*
* @param array $schema Схема.
* @param array $data Данные.
* @param array $post Запись.
*
* @return array
*/
static function ( array $schema, array $data, array $post ): array {
if ( $data['schema-type'] === 'BlogPosting' ) {
$url = esc_url( $data['main-entity'] . '#entrybody' );
$schema['url'] = $url;
$schema['mainEntityOfPage']['@id'] = $url;
}
return $schema;
},
10,
3
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment