• Resolved nartoof

    (@nartoof)


    Dear,

    I try to clean errors and warning I have with the google structured data tools.

    I have my “BlogPosting” pages working with site reviews.

    I’ve cleaned some errors adding this to my functions.php file :

    add_filter( 'site-reviews/schema/BlogPosting', function( $schema ) {
        $schema['author']['name'] = 'xxx';
        $schema['author']['type'] = 'Person';
    
       etc...
    
        return $schema;
    });

    But I don’t know how to fix it for the dynamic datas :

    -datePublished
    -headline
    -dateModified

    Is there a solution to add those data without using another structured data plugin ?

    Thank you very much for your help.

    • This topic was modified 5 years, 8 months ago by nartoof.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    According to the official schema.org documentation:

    The datePublished value is expected to be the “Date” schema type.

    And the Date schema type is expected to be a date value in ISO 8601 date format.

    To do this in PHP:

    $date = '2019-03-18';
    $datePublished = (new DateTime($date))->format(DateTime::ATOM);
    Thread Starter nartoof

    (@nartoof)

    Thank you for your reply.

    My problem isn’t how to format the date, but how to have the Published date added automatically to the schema when I post a new article.

    I’d like to add something like :

    $date = get_the_date( 'Y-m-d' , $post_id );
    $datePublished = (new DateTime($date))->format(DateTime::ATOM);
    $schema['datePublished']=$datePublished;

    But I don’t see how to fix it. Is there a solution to get the Post ID or any other solution to make it works ?

    • This reply was modified 5 years, 8 months ago by nartoof.
    Plugin Author Gemini Labs

    (@geminilabs)

    Have you tried using get_post()? This will return the global $post object.

    $post = get_post();

    Or:

    $postId = get_the_ID();

    • This reply was modified 5 years, 8 months ago by Gemini Labs.
    • This reply was modified 5 years, 8 months ago by Gemini Labs.
    Thread Starter nartoof

    (@nartoof)

    It works perfectly.

    I don’t know why I didn’t try it, I was sure it won’t works…

    Thank you very much ??

    I paste the code if it can help others :

    $date = get_the_date( 'Y-m-d H:i:s' , get_the_ID());
    	$datePublished = (new DateTime($date))->format(DateTime::ATOM);
    	$schema['datePublished']=$datePublished;
    	
    	$date = get_the_modified_time( 'Y-m-d H:i:s' , get_the_ID());
    	$dateModified = (new DateTime($date))->format(DateTime::ATOM);
    	$schema['dateModified']=$dateModified;
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add dynamic data to Json schema’ is closed to new replies.