Hello,
Thank you for reaching out and providing detailed feedback on the missing fields in the Rank Math Software Application Schema. To address your requirements for a custom PHP code to handle these missing fields automatically, you can follow the steps below:
Custom PHP Code for Software Application Schema Automation:
// Custom function to add missing fields to the Software Application Schema
function custom_software_schema_fields( $schema ) {
// Add missing field "aggregateRating" with default value of 5 stars
$schema['aggregateRating'] = array(
'@type' => 'AggregateRating',
'ratingValue' => 5,
'bestRating' => 5,
'worstRating' => 1,
'ratingCount' => 1,
);
// Add missing field "applicationCategory" with auto-picked post category
$categories = get_the_category();
$category = !empty( $categories ) ? $categories[0]->name : 'Uncategorized';
$schema['applicationCategory'] = $category;
// Add missing field "operatingSystem" with default value as Android
$schema['operatingSystem'] = 'Android';
// Add missing field "price" with default value as $0
$schema['offers'] = array(
'@type' => 'Offer',
'price' => 0,
'priceCurrency' => 'USD',
);
return $schema;
}
add_filter( 'rank_math/snippet/rich_snippet_software', 'custom_software_schema_fields' );
You can add this custom PHP code to your theme’s functions.php
file or use a custom plugin to handle this automation for your Software Application Schema.
If you encounter any issues or need further assistance, please feel free to let us know. We are here to help!
Looking forward to hearing about your success with the automated Software Application Schema setup.
Sources:
Software Schema Type » Rank Math
How to Earn Star Ratings in SERPs by Using Schema Markup With Rank Math? » Rank Math
How to Fix Aggregate Rating Error » Rank Math
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
I am using the WP Code plugin to update the snippet. I added in PHP section and make it live. Then, I edited a post and enabled the Rank Math Software SCHEMA (made no changes in it).
Then, I did a test again. And everything is the same?
Test: https://search.google.com/test/rich-results/result?id=gcIgIxTf-nKEmfUeOda0NA
Hello,
Thank you for reaching out to us.
Please disregard the previous reply from our bot.
We understand that you want to automate the addition of specific schema fields for Android applications on your website. Below is the PHP code that includes the default system as Android, price as $0, rating as 5 stars, and automatically picks the post category:
add_filter( 'rank_math/snippet/rich_snippet_softwareapplication_entity', function( $entity ) {
if ( ! is_singular( 'post' ) ) {
return $entity;
}
// Set default operating system to Android
$entity['operatingSystem'] = 'Android';
// Set default price to $0
$entity['offers'] = array(
'@type' => 'Offer',
'price' => '0',
'priceCurrency' => 'USD'
);
// Add an aggregate rating
$entity['aggregateRating'] = array(
'@type' => 'AggregateRating',
'ratingValue' => '5',
'ratingCount' => '1', // Adjust as needed
'bestRating' => '5',
'worstRating' => '1'
);
// Set application category based on post category
$categories = get_the_category();
if ( ! empty( $categories ) ) {
$entity['applicationCategory'] = $categories[0]->name;
}
return $entity;
});
We hope this helps. Please let us know if you have further questions or concerns.
Thank you.
Hello,
Please try applying this code to remove the open graph attribute.
add_filter( 'language_attributes', function( $input ) {
$input = str_replace( ' prefix="og: https://ogp.me/ns#"', '', $input );
return $input;
}, 16 );
However, this tag didn’t cause the schema error you see in the Rich Result Test. Please try the following filter to get that fixed:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
$data['place']['address']['addressCountry'] = 'BR';
return $data;
}, 99, 2);
Let us know how that goes. Looking forward to helping 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.