My Blog List

Thesis Tutorial – Custom Post Dates

The following post is part of my Thesis tutorial series. In this post, we’re going to be looking at how to customize your date display. In the past 12 months, Google has gotten much more aggressive about displaying dates in SERP listings. Since many of the sites I publish have evergreen content, they suffer from lower SERP CTR when “old” dates are shown in the SERPs.

SERP's with Dates
However, as has been pointed out, I am doing my readers a disservice by not showing the date on the post. So I’ve come up with a workaround that lets me display the date for users–but in a format that Google currently can’t extract.
This tutorial is written for Thesis (see my Thesis wordpress theme review) but can be adapted if you are using another theme. First, make sure you turn off the author’s name and date. To do this, go to thesis > design options > display options > bylines and uncheck the box.

Uncheck the published on date box
Now your post should have no date or author. Next, open up the custom functions file and create a new function. I’m calling mine “uauthor_byline”.
//this is author byline
function uauthor_byline() {

}
You’ll need some logic to display the dates only on single post pages. Here it is.
if (is_single()){ }
Inside of that function, you will need some date logic that figures out how old a post is and decides between two display variations. Set a variable for the post age, as shown below.
$daysold = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset')))/(24*60*60);
if ($daysold < 180) { } else { }

Here’s the logic to change the display based on post age. I’m going with 6 months, which is 180 days. If a post is less than 180 days, I’ll show the full date; if it’s older than 180, I’ll only show the month and year.
if ($daysold < 180){ <? the_date('F j, Y'); ?> } else {<? the_date('F Y'); ?>}
The only other thing you will need is a link with the author’s name.
<span class="headline_meta">Written by <span class="author vcard fn"><? the_author_posts_link(); ?> on </span></span><
Bring everything together like this:
//this is author byline
function uauthor_byline() {
$daysold = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset')))/(24*60*60);


if (is_single()){ ?>
<span class="headline_meta">Written by <span class="author vcard fn"><? the_author_posts_link(); ?> on </span>
if ($daysold < 180){ <? the_date('F j, Y'); ?> } else {<? the_date('F Y'); ?>}
?> </span> <?
}
}

The last thing to do is call the function in the right place. In this case, you will use the before post hook, like this:


add_action('thesis_hook_before_post','uauthor_byline' );
And here are the two variations–one just before the 180 days and one just after.



date variations
It should be noted that this is a workaround and, at some point, Google may get smart enough to interpret this or adjust its date algo. At some level, we are engaging in a bit of trickery for our own benefit. If you want to avoid this “little white lie,” you should update your evergreen content regularly and use a seasonal living URL strategy. This ensures you give the users the most up to date info without tricking anyone.
If you want to use this tutorial, it works best with the Thesis Theme. If you purchase from that link, I do receive a commission; however, I use Thesis on this website and many others and am very comfortable recommending it. If you want to spend less time playing with theme and more time creating content, Thesis is an excellent platform to do it on.
  • 50
    50
    50
    50
    50
    50
    50
    50
    50




  • 1
    1
    1
    1
    1
    1
    1
    1
    1
  • 1
    1
    1
    1
    1
    1
    1
    1
    1



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

dg3