Unable to Remove Date Snippets from Search Results

#939823
  • Resolved Christopher Hansson
    Rank Math free

    Hi there!

    I’ve attempted to go through the various guides you have regarding the subject, including:
    https://rankmath.com/kb/remove-dates-from-search/
    However, despite this I’ve been unable to remove both datePublished and dateModified from my product pages. Here’s an example URL from the website for inspection: https://www.greenbalance.se/butik/pigment/mineralpigment/ultramarinviolett/

    Here’s how my code currently looks:

    // Remove datePublished and dateModified from the JSON-LD structured data for WebPage
    add_filter( ‘rank_math/json_ld’, function( $data ) {
    if ( isset( $data[‘WebPage’] ) ) {
    $data[‘WebPage’][‘datePublished’] = ”;
    $data[‘WebPage’][‘dateModified’] = ”;
    }
    return $data;
    });

    // Remove datePublished and dateModified from the product entity and reviews
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    if ( isset( $entity[‘datePublished’] ) ) {
    $entity[‘datePublished’] = ”;
    }
    if ( isset( $entity[‘dateModified’] ) ) {
    $entity[‘dateModified’] = ”;
    }

    if ( isset( $entity[‘review’] ) ) {
    foreach ( $entity[‘review’] as $key => $review ) {
    if ( isset( $review[‘datePublished’] ) ) {
    $entity[‘review’][$key][‘datePublished’] = ”;
    }
    if ( isset( $review[‘dateModified’] ) ) {
    $entity[‘review’][$key][‘dateModified’] = ”;
    }
    }
    }

    return $entity;
    });

    // Remove Open Graph date properties
    add_filter( ‘rank_math/opengraph/facebook/og_updated_time’, ‘__return_false’ );
    add_filter( ‘rank_math/opengraph/facebook/article_published_time’, ‘__return_false’ );
    add_filter( ‘rank_math/opengraph/facebook/article_modified_time’, ‘__return_false’ );

    // Remove lastmod from sitemap index
    add_filter( ‘rank_math/sitemap/index/entry’, function( $entry, $type ) {
    if ( isset( $entry[‘lastmod’] ) ) {
    unset( $entry[‘lastmod’] );
    }
    return $entry;
    }, 10, 2 );

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting us and bringing your concern to our attention.

    You can use the following filter to remove the datePublished and dateModified properties from the itemPage Schema:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	if(is_product()) {
    		unset ($data['WebPage']['dateModified']);
    		unset ($data['WebPage']['datePublished']);
    		return $data;
    	}
    	return $data;
    }, 9999, 2);
    

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    That seemed to work, thank you!

    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/#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.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Unable to Remove Date Snippets from Search Results’ is closed to new replies.