Forked from mihdan/wp-schema-pro-filter-blog-posting.php
Created
January 3, 2024 17:18
-
-
Save Shoora/0061d2920cdfd01df3ce2592f8b40745 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