Article schema – CommentAction

#702434
  • 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 CommentAction to the article schema.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hello, we appreciate your query. To add the CommentAction to the Article Schema in Rank Math, you can use the following filter:

    add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
        $entity['comment'] = array(
            '@type' => 'CommentAction',
            'text' => 'Your comment text here',
        );
        return $entity;
    });

    This filter will add the CommentAction to the Article Schema. 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
    How to Fix Aggregate Rating Error » Rank Math
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    How to Add Sitelinks Searchbox Schema to All Pages » Rank Math
    The #1 WordPress SEO Plugin in 2023 – Rank Math

    1. It should contain “commentCount”: 25 , . It will be auto generate depends on the numbers of comments.

    2. It should be populated like this

    ” “potentialAction”: [
    {
    “@type”: “CommentAction”,
    “name”: “Comment”,
    “target”: [
    “https: example . com/#respond”
    ]

    The URL will be automatically generated.

    Target should be URL#respond

    Hello,

    Thank you for contacting Rank Math support.

    1. You can use the get_comments_number() function to get the number of comments for the current post. For example:

    $entity['commentCount'] = get_comments_number();
    

    2. You can use the get_permalink() function to get the URL of the current post and append the #respond fragment to it. For example:

    $entity['potentialAction'] = array(
      array(
        '@type' => 'CommentAction',
        'name' => 'Comment',
        'target' => array(
          get_permalink() . '#respond'
        )
      )
    );

    Please review this and let us know if it achieved your desired result. If you have any other questions or issues, please don’t hesitate to contact us again.

    Thank you for choosing Rank Math

    Critical error….

    I added the code blow to my function PHP.

    add_filter( ‘rank_math/snippet/rich_snippet_article_entity’, function( $entity ) {
    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    )
    )
    );

    PleaseCan Ike help

    Still have error using add_filter( ‘rank_math/snippet/rich_snippet_article_entity’, function( $entity ) {
    $entity[‘comment’] = array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    $entity[‘commentCount’] = get_comments_number();

    );
    return $entity;
    });

    Hello,

    The filter you’re using missing a closing bracket. Please try to use the following one and see if that works for you:

    add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
      $entity['potentialAction'] = array(
      array(
        '@type' => 'CommentAction',
        'name' => 'Comment',
        'target' => array(
          get_permalink() . '#respond'
        )
      )
    );
    });
    

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    add_filter( “rank_math/snippet/rich_snippet_article_entity”, function( $entity ) {
    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    )
    )
    );
    });
    Above Disabled the output of article schema.

    Direct me to https://support.rankmath.com/users/ikechukwun/

    I guess I might rescue me.

    I also want

    Hello,

    To help you investigate this issue, we might need to take a closer look at your website and settings. Please follow these steps:

    • Edit the first post on this ticket and include your WordPress and FTP logins in the Sensitive Data section. This is a secure section that only our support staff can access.
      Sensitive Data Section
    • Make sure you take a complete backup of your website before sharing the information with us.
    • If you prefer, you can use this plugin to generate a temporary login URL to your website and share that with us instead: https://wordpress.org/plugins/temporary-login-without-password/
    • You can also use this plugin to monitor what changes our staff might make on your website (if any): https://wordpress.org/plugins/wp-security-audit-log/

    We appreciate your cooperation and patience. Thank you for choosing Rank Math.

    Please can you just direct me to Ike. The code he and one other person sent regarded to wordcount, articleBody and Required time for the article schema work perfectly. I which I could open that support tick so they can reply me me there.
    Here is the link to their response https://support.rankmath.com/ticket/article-schema-9/

    I want code that will be able to add comment action

    Such that it will populate;

    1. The numbers of comments ( comment count)

    2. Url of the post (https: example . com/#respond)

    When you analysis yoast SEO you will see the comments action there .

    Hello,

    The issue is that you have the filter added multiple times and as such only the last one gets added to the page.

    You need to add all the information inside a single filter so that everything gets added.

    For example, in the same filter you have the articleBody working you should also add the same inside:

    
    $entity['potentialAction'] = array(
      array(
        '@type' => 'CommentAction',
        'name' => 'Comment',
        'target' => array(
          get_permalink() . '#respond'
        )
      )
    );
    

    Don’t hesitate to get in touch if you have any other questions.

    add_filter( “rank_math/snippet/rich_snippet_article_entity”, function( $entity ) {
    $entity[‘articleBody’] = wp_strip_all_tags(get_the_content());
    return $entity;
    });
    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    )
    )
    );

    I should add it like above

    Or add_filter( “rank_math/snippet/rich_snippet_article_entity”, function( $entity ) {
    $entity[‘articleBody’] = wp_strip_all_tags(get_the_content());
    return $entity;
    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    )
    )
    );
    });

    Or

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

    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    ),
    ),
    );

    return $entity;
    });

    Thank you all my issues has been resolved… With all you helps and I ChatGPT just helped me to combine them and they work like charm and output all that is required.

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

    $entity[‘potentialAction’] = array(
    array(
    ‘@type’ => ‘CommentAction’,
    ‘name’ => ‘Comment’,
    ‘target’ => array(
    get_permalink() . ‘#respond’
    ),
    ),
    );

    $entity[‘commentCount’] = get_comments_number();

    // 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;
    });

    /**
    * Allow developer to disable the breadcrumb json-ld output.
    *
    * @param bool $unsigned Default: true
    */
    add_filter( ‘rank_math/json_ld/breadcrumbs_enabled’, ‘__return_false’ );

    Hello,

    Awesome! 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 13 replies - 1 through 13 (of 13 total)

The ticket ‘Article schema – CommentAction’ is closed to new replies.