• Resolved dsbelousov

    (@dsbelousov)


    Hi,

    I’ve started using your plugin and I love it! There is one thing I can’t figure out yet.

    One of the fields in BlogPosting is “datePublished 2018-08-02T14:53:17+00:00” which I need to remove from the markup.

    Can you please let me know how can this be done?

    Thank you!

    Dmitry

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Hesham Zebida

    (@hishaman)

    Hi Dmitry,

    You can override values of markup using the schema_output filter. Here is an example of how to remove datePublished property as well as the dateModified property:

    add_filter('schema_output', 'remove_datePublished_markup_588545256');
    /**
     * Schema Plugin: Remove datePublished markup on BlogPosting
     *
     * @since 1.0
     */
    function remove_datePublished_markup_588545256( $schema ) {
    	
    	// If markup is for BlogPosting,
    	// return our $json array and do not do anything
    	if ( isset($schema['@type']) && $schema['@type'] != 'BlogPosting' ) ) return $schema;
    	
    	// Unset the published date
    	unset( $schema["datePublished"] );
      
    	// unset the modified date (last updated date)
    	unset( $schema["dateModified"] );
    		 
    	return $schema;
    }

    Here is a link to documentation page and code gist.

    Note: After you add this snippet, make sure you cleared cache (if you use any), and save the plugin settings once for changes to take place.

    I hope this helps.

    Hi Hesham!

    Thank you for your help! But here is my problem: when I add that code to theme’s functions.php, the website stops working – I can’t even access dashboard. Tried to deactivate plugin, still the same issue.

    What can cause it?

    UPD: My PHP version is 7.2

    Thanks in advance!

    Regards,
    Artem

    • This reply was modified 5 years, 10 months ago by artemt. Reason: Update
    Plugin Author Hesham Zebida

    (@hishaman)

    @artemt

    My bad, I did a mistake in the code, sorry about that. I’ve updated the gist.

    Here is the working code:

    add_filter('schema_output', 'remove_datePublished_markup_588545256');
    /**
     * Schema Plugin: Remove datePublished markup on BlogPosting
     *
     * @since 1.0
     */
    function remove_datePublished_markup_588545256( $schema ) {
    	
    	// If markup is for BlogPosting,
    	// return our $json array and do not do anything
    	if ( isset($schema['@type']) && $schema['@type'] != 'BlogPosting' ) return $schema;
    	
    	// Unset the published date
    	unset( $schema["datePublished"] );
      
    	// unset the modified date (last updated date)
    	unset( $schema["dateModified"] );
    		 
    	return $schema;
    }

    Note: Removing the published date will show an error in Google’s Structured Data Testing Tool, so be aware of that.

    Hello !

    I’m trying to accomplish the same thing, i’ve copied your code but the datePublished is still there.
    I’ve also tried to comment all lines of the plugin with the datePublished and it still there … I don’t understand.

    Would you have any idea of my issue ?

    Plugin Author Hesham Zebida

    (@hishaman)

    Hi @jerome38190 ,

    After you add this snippet, make sure you cleared cache (if you use any), and save the plugin settings once for changes to take place.

    Thank you Hesham for the updated code!

    Note: Removing the published date will show an error in Google’s Structured Data Testing Tool, so be aware of that.

    Is it a bad thing for rankings or it’s only a notification in Structured Data tool?

    I just want Google to show update dates in SERP instead of publish ones.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to remove datePublished from the markup?’ is closed to new replies.