Add a Customer Service Contact to Rank Math's Organization
Adds a ContactPoint with phone, email and languages to the Organization entity Rank Math outputs on your site.
Opens WPIDE on
Code
// Contact details.
$wpide_rm_contact = array(
'telephone' => '+1-555-010-0101',
'email' => '[email protected]',
'contactType' => 'customer service',
'availableLanguage' => array( 'English', 'Spanish' ),
);
add_filter( 'rank_math/json_ld', function ( $data ) use ( $wpide_rm_contact ) {
if ( ! is_array( $data ) ) {
return $data;
}
foreach ( $data as $key => $entity ) {
$types = isset( $entity['@type'] ) ? (array) $entity['@type'] : array();
if ( in_array( 'Organization', $types, true ) ) {
$data[ $key ]['contactPoint'] = array_merge( array( '@type' => 'ContactPoint' ), array_filter( $wpide_rm_contact ) );
}
}
return $data;
}, 99 );
Notes
Only applies when Rank Math describes the site as an organization, not a person.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.