Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Rank Math will extract the values of the datePublished and dateModified from the $_POST data when the post is published. It is likely that this data is not available in the $_POST when creating posts with the Knowledgebase plugin.
You can however assign these values by using the following filter on your theme’s functions.php file:
/**
* Filter to add Brand Name for Products.
*
* @param array $entity Snippet Data
* @return array
*/
add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
global $post;
//get datePublished & dateModified from the third party plugin
$entity['datePublished'] = $value;
$entity['dateModified'] = $value2;
$entity['author']['name'] = 'Name';
return $entity;
});
Looking forward to helping you. Thank you.
​​​​​​​
Hi Michael,
Thank you for the hint and code sample! We ended up retiring the KB plugin and made our own custom post type with Types. The new custom post type had the same issue so I added code as you suggested.
Here is what we ended up adding in case it’s helpful for others in the future. This should be general enough to get the correctly formatted information from any post in WordPress:
add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
global $post;
//get datePublished & dateModified from the third party plugin
$entity['datePublished'] = get_post_time( 'Y-m-d\TH:i:s', false, $post, true );
$entity['dateModified'] = get_post_modified_time( get_option( 'Y-m-d\TH:i:s' ), false, $post, true );
$entity['author']['name'] = get_the_author_meta( 'nickname', get_the_author_meta( 'ID' ) );
return $entity;
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.