Support » Plugin: kk Star Ratings » How to use different schema markup for custom post type

  • Resolved examcraze123

    (@examcraze123)


    Hi,

    By default we can setup schema markup for whole site using kk star rating >> Rich Snippets >> Content.

    {
        "@context": "https://schema.org/",
        "@type": "CreativeWorkSeries",
        "name": "{title}",
        "aggregateRating": {
            "@type": "AggregateRating",
            "ratingValue": "{score}",
            "bestRating": "{best}",
            "ratingCount": "{count}"
        }
    }

    I want to pass different schema markup for custom post type?

    How can I achieve that?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Kamal Khan

    (@bhittani)

    You may do that in your custom post type template/theme file.

    For more information on how to achieve this, take a look at this topic:

    https://wordpress.org/support/topic/how-to-enable-variables-to-custom-rich-snippets

    Thread Starter examcraze123

    (@examcraze123)

    Can you please show me how to echo these value?

    {title} Post title
    {score} Average ratings
    {count} Number of votes casted
    {best} Total amount of stars`

    Plugin Author Kamal Khan

    (@bhittani)

    In the second argument where it says “custom schema goes here”. This is where you should enter your schema.

    Thread Starter examcraze123

    (@examcraze123)

    <?php
    if (function_exists('Bhittani\StarRating\core\functions\ld_json')) {
        echo \Bhittani\StarRating\core\functions\ld_json(
            
            ['id' => 'post id goes here'], 
            
            '{
                "@context": "https://schema.org/",
                "@type": "CustomSchema",
                "name": "{title}",
                "aggregateRating": {
                    "@type": "AggregateRating",
                    "ratingValue": "{score}",
                    "bestRating": "{best}",
                    "ratingCount": "{count}"
                }
            }');
    }

    Thisone is correcy way?

    also how to grab single cpt post ids

    Plugin Author Kamal Khan

    (@bhittani)

    Yes that is correct. It will automatically get the current id if you dont pass the ‘id’ key. Otherwise you can set ‘id’ to get_the_ID()

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to use different schema markup for custom post type’ is closed to new replies.