can you provide example of modifying scheme

  • I see the response to many tickets that it’s possible to modify schema data. Can you provide an example of this?

    I see you reference this code snippet:

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

    But need an example of say appending some sort of data that includes a custom field from a post of page type?

Viewing 5 replies - 1 through 5 (of 5 total)
  • As I explore this filter now:
    1. Seems to escape all the quotes, but wont work unless I have quotes
    2. Adds it as graph data. In my scenario, in certain scenarios, I want to append the following to an organization schema:

    location: [
      {
       SOME SCEMA of my franchise location 1
      },
      {
       SOME SCEMA of my franchise location 2
      },
      {
       SOME SCEMA of my franchise location 3
      }
    ]

    Any thoughts would be helpful! Want to use what I can from your plugin and then evolve it.

    THanks

    Anybody around…so trying to get something working, following the example provided by another support tech here:
    https://support.rankmath.com/reply/64995/

    In this example he modifies the Organization schema (which is my goal) but this example is non responsive.

    Any help on modifying the schema for organization would be great! Final goal is to add items (like sameAs, and location, where location would be an array of restaurant types for all the locations)

    If anybody has any ideas…let me know

    Hello Ben,

    Thank you for contacting Rank Math today.

    Here is a filter I have tested and is working from my end:

    
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
        if ( isset( $data['Organization'] ) ) {
            $data['Organization']['location'] = ['somelocation', 'someotherlocation'];
        }
        return $data;
    }, 99, 2 );
    

    Looking forward to helping you. Thank you.

    ​​​​​​

    Thanks @michaeldavis

    So the problem for me what the https://rankmath.com/kb/filters-hooks-api-developer/#extend-json-ld-data example sets the position priority of the filter to 10 where yours is set to 99…that was my main source of frustration.

    Your code in the filter

    if ( isset( $data['Organization'] ) ) {
            $data['Organization']['location'] = ['somelocation', 'someotherlocation'];
    }

    Would not work because if using 10 as the filter priority…$data will never have data.

    Anyways important point to note. But now that i see the documentation bug everything is good on my end and I’m excited to play with it and hopefully that helps you as well to help others!

    -Ben

    Hello,

    We have updated the filter.

    Thank you for bringing that to our attention.

    If you need help with anything else, please open a new support ticket here so we can help:

    https://support.rankmath.com

    We are always here for assistance.

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

The ticket ‘can you provide example of modifying scheme’ is closed to new replies.