How to change the publish date on WordPress for Google search results - React to WordPress
How to modify the publish date on Google search results

How to change the publish date on WordPress for Google search results

Maybe I’m a little slow, but for me, it took a while to understand why is it Google so stubborn to not taking into consideration my modified date and showing it in the search results. After adding million of useless tags – I have found the solution for it.

Before we start…

I know you probably tried and searched functions, methods, tags like Last modified, dateModified, dateCreated and much more – those tags are not being used by Google in a direct way(as it is not part of the “rich data” information that’s appearing on the search results).

This article will show you a 100% solution for showing and modifying the times Google is showing in the search results.

But, is it dangerous?

It is for you to find out, Don’t overuse it though.

I only encourage you updating the publish date when you actually did a significant update to your article, not just updating the publishing date without adding fresh information for the user.

I am afraid Google could remove pages or even websites that just updating the publishing date without actually adding any content to it.

Is modifying publishing date helping to rank faster or higher?

I am not sure, but I think it can affect how users see your website and that alone will help it to rank higher and be crawled faster.

With that being said, Three of our clients are huge news websites(together hitting more than 100m unique users monthly). After we applied these methods we saw that pages started to update on google much faster(2-3x times faster) and staying on top for far longer than previously(for trending topic and Google news).

This article will show you:

  1. How to change publish date on WordPress
  2. How to get Google to notice that change and show in the search results.
  3. A way of adding an automatic publish date change checkbox

How to change the publish date on WordPress

  1. Go to the post you want to change the publish date on
  2. Find the publish box and click the Edit button left to the “Publish” and update the date.
    Publish box to modify serp engine data publish box open for updating google modified date

How to update Google regarding the newly updated last modified date / last published date

I already wrote that Google is not into consideration some of the schema tags when it is updating it’s “rich data” information on the search results page, but there is one tag that is the key to it all – the datePublished.

If you already have http://schema.org code inside your page and you know where to change it – just add this line to the end of it – before the }:

,"datePublished":"<?php echo get_the_date( 'Y-m-d\TH:i:s', $post->ID ); ?>+00:00", // Will appear on google

Add with the a ,.

If you don’t have any schema information on your page, you will have to add it to every post on your page with a hook, just like that:

add_action( 'wp_head', 'cj_ld_json_schema_for_single' );
function react2wp_update_published_date_on_google() {
   if ( is_single() ) : global $post; ?>
        <script type="application/ld+json">
            {
                "@context": "http://schema.org",
                "@type": "NewsArticle", // You can change NewsArticle to TechArticle

                "mainEntityOfPage": {
                    "@type":"WebPage",
                    "@id":"<?php echo get_permalink( $post->ID ); ?>"
                },
                "author": {
                    "@type":"Person",
                    "name":"<?php echo get_the_author_meta( 'display_name', $post->post_author ); ?>"
                },
                "headline":"<?php the_title(); ?>",
                "url":"<?php echo get_permalink( $post->ID ); ?>",
                "thumbnailUrl":"<?php echo get_the_post_thumbnail_url( $post->ID, 'full' ); ?>",
                "description":"<?php echo get_post_meta( get_the_ID(), '_yoast_wpseo_metadesc', true ); ?>",
                "datePublished":"<?php echo get_the_date( 'Y-m-d\TH:i:s', $post->ID ); ?>+00:00", // Will appear on google

            }

        </script>
   <?php endif;
}

Add this action to the end of your theme’s functions.php file through your favorite FTP client or through Appearance > Editor > functions.php in WordPress panel.

How to update publishing date on Google easier and faster?

In the images added above, you was able to see a small checkbox with a label of “Force update publish date” in the publishing box.

Every time you will check that box and click “Update” to update the post, this will activate the action that will change the publish date of the post to the current time without doing anything else manually.

add_action( 'post_submitbox_misc_actions', 'react2wp_update_publishing_date' );
add_action( 'save_post', 'react2wp_update_publishing_date__save', 10, 2 );

function react2wp_update_publishing_date() {
   $nonce   = wp_nonce_field( '_cj_update_publishing_date', '_cj_update_publishing_date_nonce', TRUE, FALSE ); ?>
   <div class="misc-pub-section cj-update-publishing-date">
      <label for="cj-update-publishing-date">
         <input type="checkbox" id="cj-update-publishing-date" name="cj_update_publishing_date" value="1" />
         <strong>Force update publish date</strong>
         <?php echo $nonce ?>
      </label>
   </div>
<?
 }

function react2wp_update_publishing_date__save( $post_id )
{
   if ( wp_is_post_revision( $post_id ) ) {
      return;
   }

   if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
      return;
   }

   if ( ! current_user_can( 'edit_post', $post_id ) ) {
      return;
   }

   // IF CHECKBOX IS EMPTY OR NOT

   if ( ! isset ( $_POST[ 'cj_update_publishing_date' ] ) ) {
      return;
   }

   // CHECK NONCE

   if ( ! wp_verify_nonce( $_POST[ '_cj_update_publishing_date_nonce' ], '_cj_update_publishing_date' ) ) {
      return;
   }

   $time = current_time('mysql');

   remove_action('save_post', 'react2wp_update_publishing_date__save');

   wp_update_post(
      array (
         'ID'            => $post_id, // ID of the post to update

         'post_date'     => $time,
         'post_date_gmt' => get_gmt_from_date( $time )
      )
   );

   add_action( 'save_post', 'react2wp_update_publishing_date__save' );
}

Add this action to the bottom of the functions.php inside of your activated theme the same way you added the schema data.

Summary

So now you understand that the tag datePublished is extremely important, but it’s not mean that Google ignores every other tag in the schema regarding dates. Google could still be using this information indirectly to rank your site better/faster/smarter.

Continue following the schema guidelines to get the maximum of the SEO goodness Google allows us to know about.

That’s it for this article, now you are ready to start publishing fresh content without worrying if Google will see it or not!

 

Best WordPress hosting? SiteGround. Cheap, Fast and Friendly to Developers! 3.95$/Month

Leave a Reply

Your email address will not be published. Required fields are marked *