hook for Schema

#236622
  • Hello. Can I take some fields not from WordPress when forming a schema (for example business type), but using a hook from the side for the WordPress database. For example, I want to take the name of the organization and its telephony through the API of a third-party site (vk.kom) and substitute them through a hook into the scheme generated by the SEO Rank Match plugin. If possible, then with a small code example. I found rank_math / json_ld hooks in the help but did not understand how to use it. Or through another hook?

Viewing 1 replies (of 1 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting us and we’re really sorry for the unfortunate delay.

    If the third party is using JSON format, then you can use the below filter:

    add_filter( 'rank_math/json_ld', function( $json_ld, $json ) {
       
            $json_ld['snippet'] = [
                '@context'         => 'https://schema.org',
                '@type'            => \RankMath\Helper::get_settings( "titles.pt_{$json->post->post_type}_default_article_type" ),
                'name'         => $json->parts['name'],
                'telephone'      => $json->parts['telephone'],
            ];
            $json->add_prop( 'thumbnail', $json_ld['snippet'] );
      
        return $json_ld;
    }, 11, 2);

    Please replace parts['name'] and parts['telephone'] with the relevant data.

    Hope that helps.

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

The ticket ‘hook for Schema’ is closed to new replies.