Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @nalitana

    Thank you for contacting the support.

    Since Google’s tool is accepting the current Schema Markup, please use the following filter in your theme’s functions.php file to make it compatible with Yandex as well:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
        $parts = [];
    
        if ( isset( $data['CollectionPage'] ) ) {
            unset( $data['CollectionPage']['hasPart'] );
            while ( have_posts() ) {
                the_post();
                $post_id = get_the_ID();
                $schema  = RankMath\Helper::get_post_meta( 'rich_snippet', $post_id );
                if ( ! $schema || 'article' !== $schema ) {
                    continue;
                }
    
                $title = $jsonld->get_post_title( $post_id );
                $url   = $jsonld->get_post_url( $post_id );
                $parts[] = [
                    '@type'            => isset( $data['schema'] ) ? $data['schema'] : $schema,
                    'headline'         => $title,
                    'name'             => $title,
                    'url'              => $url,
                    'mainEntityOfPage' => $url,
                    'dateModified'     => get_post_modified_time( 'Y-m-d\TH:i:sP', true ),
                    'datePublished'    => get_post_time( 'Y-m-d\TH:i:sP', true ),
                    'author'           => $jsonld->get_author(),
                    'publisher'        => $jsonld->get_publisher( $data ),
                    'image'            => $jsonld->get_post_thumbnail( $post_id ),
                    'keywords'         => $jsonld->get_post_terms( $post_id ),
                    'commentCount'     => get_comments_number(),
                    'comment'          => $jsonld->get_comments( $post_id ),
                    'wordCount'        => str_word_count( get_the_content() ),
                ];
            }
    
            wp_reset_query();
    
            $data['CollectionPage']['hasPart'] = $parts;
        }
    
        return $data;
    }, 99, 2);

    Hope that helps.

    Thread Starter Natalya

    (@nalitana)

    Hello! Thank you very much for your answer! It turns out that the problem is only one letter. @type “article” written in small letters. That sounds ridiculous, but Yandex needs the capital letter A (@type “Article”). Could you change the letter in the next update? And yet, if for a single entry, BlogPosting is a markup type, is it possible to make it so that we can choose the same type for a page with categories, instead of Article type?

    Thread Starter Natalya

    (@nalitana)

    Thanks for the update! You are just incredible. Work with cosmic speed.)

    Plugin Author Rank Math

    (@rankmath)

    Hello @nalitana

    Glad the update helped.

    Please feel free to open a new support topic if you need any assistance in the future.

    Good day.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘HasPart contains an invalid type’ is closed to new replies.