CUSTOM SCHEMA

#83159
  • Resolved Bergen
    Rank Math free

    I am using Rankmath for basic schema.

    Is there a way to write in custom schema with Rankmath??

    Seopress has that feature that allows you to write in custom schema for pages and posts and am wondering if that is possible with Rankmath.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    You can make use of the following filter to extend json+ld data. Once you have customized it, you can add it to your active theme functions.php file.

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

    Looking forward to helping you. Thank you.

    ​​​​​​

    Ben
    Rank Math business

    @michaeldavis still struggling with getting this to work

    Can you provide a working example, i have another thread on this as well but perhaps it would be best handled here.

    1. Looking to add the location field to the schema for the organization
    2. Looking to make the location field and array of schema type Restaurant with each item of the array being the full restaurant details using, ie final output being:

    location: [
    {
      "@context": "https://schema.org",
      "@type": "Restaurant",
      "parentOrganization": {
         "@id":"https://something.com/#organization"
       },
      "name": "something Restaurant - Burbank",
      "image": "https://something.com/yes-logo-and-bar-03.jpg",
      "@id": "https://something.com/locations/burbank/#Restaurant",
      "url": "https://something.com/locations/burbank/",
      "telephone": "+18185242288",
      "priceRange": "$10 - $40",
      "menu": "https://something.com/locations/burbank/",
      "servesCuisine": ["Asian", "Sushi", "Japanese", "Chinese"],
      "acceptsReservations": "false",
      "address": {
        "@type": "PostalAddress",
        "streetAddress": "150 S. something #20",
        "addressLocality": "Burbank",
        "addressRegion": "CA",
        "postalCode": "91502",
        "addressCountry": "US"
      },
      "geo": {
        "@type": "GeoCoordinates",
        "latitude": 34.1806046,
        "longitude": -118.3079324
      },
      "openingHoursSpecification": {
        "@type": "OpeningHoursSpecification",
        "dayOfWeek": [
          "Monday",
          "Tuesday",
          "Wednesday",
          "Thursday",
          "Friday",
          "Saturday",
          "Sunday"
        ],
        "opens": "11:00",
        "closes": "00:00"
      },
      "sameAs": [
        "https://www.instagram.com/somethingburbank/",
        "https://www.facebook.com/somethingBurbank",
        "https://something.com/locations/burbank/"
      ] 
    }
    ]

    Any guidance would be appreciated.

    Alberto
    Rank Math business

    Hello,

    I will share with you an example code so you will see how JSON code should be added (this code adds a FAQPage schema but could be modified to fit your code):

    /**
     * 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 ) {
    	$data = [
    			'@context'       => 'https://schema.org',
    			'@type'          => 'FAQPage',
    			'mainEntity'     => [
    				'@type' => 'Question',
    				'name'  => 'Question one',
    				'acceptedAnswer' => [
    					'@type'  => 'Answer',
    					'text'   => 'Answer one',
    				],
    			],
    		    'mainEntity'     => [
    				'@type' => 'Question',
    				'name'  => 'Question Two',
    				'acceptedAnswer' => [
    					'@type'  => 'Answer',
    					'text'   => 'Answer Two',
    				],
    			],
    		];
    	return $data;
    }, 10, 2);

    Looking forward to help you.

    Ben
    Rank Math business

    Thanks I had got this working, heads up the priority you set your filter to activate wont work.
    }, 10, 2);

    it needs to be something like
    }, 99, 2);

    Alberto
    Rank Math business

    Hello,

    Thank you for sharing that, I will share it with the documentation team so they can modify it.

    Do you have any other questions or do you want us to close this thread?

    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 ‘CUSTOM SCHEMA’ is closed to new replies.