Article Schema

#701142
  • Resolved EJES GIST
    Rank Math free

    add_filter( “rank_math/snippet/rich_snippet_article_entity”, function( $entity ) {
    $entity[‘articleBody’] = wp_strip_all_tags(get_the_content());
    return $entity;
    });

    I used above to add articleBody to the rank maths article schema…

    What will I do to add wordcount to the article schema.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello, I understand that you’ve successfully added the articleBody to the Rank Math’s article schema. To add the wordcount to the article schema, you can use the following code snippet:

    add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
        $entity['wordcount'] = str_word_count( wp_strip_all_tags( get_the_content() ) );
        return $entity;
    });

    This code snippet will add the wordcount to the article schema. Once you’ve added this code snippet, make sure to save the changes.

    If you have any further questions or need additional assistance, please feel free to ask.

    Sources:
    How to Remove Keywords Data from Article Schema » Rank Math
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    The #1 WordPress SEO Plugin in 2023 – Rank Math
    How to Fix Aggregate Rating Error » Rank Math
    Remove Organization Schema from Your Website » Rank Math

    EJES GIST
    Rank Math free

    I still need filter for adding timerequired for the article schema

    Hello,

    Thank you for your patience.

    To add the timeRequired in the article schema, please update the code above and use this instead:

    add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
    	$entity['wordcount'] = str_word_count( wp_strip_all_tags( get_the_content() ) );
        $entity['timeRequired'] = 'PT18M19S';
        return $entity;
    });

    You may update the time as well to match your actual data.

    Hope that helps.

    EJES GIST
    Rank Math free

    I want the time to automatically generate or populate… And above will not work …

    Hello,

    You can use this filter code to automatically generate the timeRequired:

    add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
        // Calculate the time required based on the average reading speed (words per minute)
        $average_reading_speed = 200; // Adjust this value based on your estimation
        $wordcount = str_word_count( wp_strip_all_tags( get_the_content() ) );
        $time_required_minutes = ceil( $wordcount / $average_reading_speed );
    
        // Format the time in ISO 8601 duration format
        $hours = floor( $time_required_minutes / 60 );
        $minutes = $time_required_minutes % 60;
    
        $entity['wordcount'] = $wordcount;
        $entity['timeRequired'] = 'PT' . $hours . 'H' . $minutes . 'M';
    
        return $entity;
    });

    You can adjust the reading speed value ($average_reading_speed) according to your audience’s typical reading pace. We used 200 words per minute in the code.

    We hope this helps. Please let us know if you have further questions or concerns.

    Thank you.

    EJES GIST
    Rank Math free

    It works perfect… God bless you Ike.

    Hello,

    We’re delighted to hear that this issue has been resolved. We appreciate your kind words and your support.

    I’m closing this ticket now but if you ever have another question or need any help in the future, please don’t hesitate to create a new forum topic. We’ll be more than happy to assist you again.

    Thank you for choosing Rank Math and have a wonderful day!

    Cheers

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Article Schema’ is closed to new replies.