Created
July 10, 2023 09:53
-
-
Save mihdan/04f6a0c5b263d847574fa55d5da28e46 to your computer and use it in GitHub Desktop.
Расширяет микроразметку BlogPosting в плагине WP Schema Pro для получения контентной аналитики (дочитываемость, категории, автора, тематики) в Яндекс.Метрике
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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