How can I add another Schema Type

#75783
  • Resolved Gap Genious
    Rank Math free

    Hi, this is an awesome plugin. I’ve always (almost blindly) used a competitor plugin and now this is a great option.

    I wish to add the schema type LodgingBusiness to Rank Math and use it on one of our Custom Post Types.

    I’ll do this on our child theme’s functions.php. Can you point me to any hooks I should use to add this schema type?

    Thank you.

    Peter

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Assuming your site is about Lodging business, you can set the Lodging business as your business type in Rank math > Titles & Meta > Local SEO and use Service schema or article schema on your posts.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Thanks Michael for your reply. I actually want to apply the Lodging Business to a specific Custom Post Type page. Then I wish to apply schema for rooms, offers, etc. to other sub pages.

    Is there anyway we can expand the schemas on individual posts via some coding and hooks?

    Thanks.
    Peter

    Hello,

    In that case, you can customize the following filter and add it to your theme’s functions.php:

    
    /**
     * Collect data to output in JSON-LD.
     *
     * @param array  $unsigned An array of data to output in json-ld.
     * @param JsonLD $unsigned JsonLD instance.
     */
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	return [];
    }, 10, 2);
    

    Hope that helps. If you have any further question(s), please let us know. Thank you.

    Thanks Michael, would you happen to have a small example of the use of this filter?

    Alberto
    Rank Math business

    Hello,

    Yes, of course, here you are:

    /**
     * Collect data to output in JSON-LD.
     *
     * @param array  $unsigned An array of data to output in json-ld.
     * @param JsonLD $unsigned JsonLD instance.
     */
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
            // I added this conditional here since maybe you want to use
            // this schema only in a particular page
            // You can modify it to be shown wherever you want
            if(is_singular('post type name here')){
            // Remember to change the 'schema type' name with
            // the official schema name (like 'Article')
            // You can see the full list here: https://schema.org/docs/full.html
            // After that, just customize the array with the Schema parameters
            // (Not necessary the ones that I have set there)
    	$data['schema type'] = [
    			'@context' => 'https://schema.org',
    			'@type'    => '',
    			'@id'      => '',
    			'name'     => '',
    			'url'      => '',
    			'sameAs'   => '',
    		];
    	return $data;
    	}
    	return [];
    }, 10, 2);

    Looking forward to help you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘How can I add another Schema Type’ is closed to new replies.