Auto fill schema fields with custom fields

#99727
  • Resolved Dave
    Rank Math free

    Hi. I’ve been using RM for a while now and I really like it. Well done on all the hard work you’ve all put in.

    Can you please assist me in where I’m going wrong? I have read this ticket https://support.rankmath.com/ticket/%E2%98%85-pre-fill-schema-fields-using-custom-fields/ and I’m trying to do it myself but it doesn’t seem to be working.

    Do you know where I’ve gone wrong? My function code is below:

    /**
      * Filter to change the schema data.
      * Replace $schmea_type with schema name like article, review, etc.
      * @param array $entity Snippet Data
      * @return array
      */
     add_filter( 'rank_math/snippet/rich_snippet_JobPosting_entity', function( $entity ) {
    
      /* Here you would get the data from the custom fields and fill your schema */
      $entity = array(
        'jobLocation' => array(
          '@type' => 'Place',
          'address' => array(
            '@type' => 'PostalAddress',
            'streetAddress' => 'TEST Address',
            'addressLocality' => ', Test Local',
            'addressRegion' => 'Test Region',
            'postalCode' => 'Test Post code',
            'addressCountry' => 'UK',
          ),
        ),
        'baseSalary' => array(
          '@type' => 'MonetaryAmount',
          'currency' => 'USD',
          'value' => array(
            '@type' => 'QuantitativeValue',
            'value' => 40.00,
            'unitText' => 'HOUR'
          ),
        ),
      );
    
      return $entity;
     });
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for getting in touch with us.

    Please try using the code as shown below:

    
    add_filter( 'rank_math/snippet/rich_snippet_JobPosting_entity', function( $entity ) {
    
      /* Here you would get the data from the custom fields and fill your schema */
      $entity['jobLocation'][] = [
          '@type' => 'Place',
          'address' => [
            '@type' => 'PostalAddress',
            'streetAddress' => 'TEST Address',
            'addressLocality' => ', Test Local',
            'addressRegion' => 'Test Region',
            'postalCode' => 'Test Post code',
            'addressCountry' => 'UK',
          ],
        ],
        $entity['baseSalary'][] = [
          '@type' => 'MonetaryAmount',
          'currency' => 'USD',
          'value' => [
            '@type' => 'QuantitativeValue',
            'value' => 40.00,
            'unitText' => 'HOUR'
          ]
        ];
    
      return $entity;
     });
    

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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 1 replies (of 1 total)

The ticket ‘Auto fill schema fields with custom fields’ is closed to new replies.