How to make friends with the Hide My Dates plugin and the Twentytwelve theme

How to make friends with the Hide My Dates plugin and the Twentytwelve theme

Greetings! In this article, I’ll explain why it’s important to hide post and comment publication dates, and how I managed to make the “Hide My Dates” plugin work with the “Twentytwelve” theme I use on my site.

When creating my first WordPress site, I had to read many articles about WordPress itself and its popular plugins. Along the way, I kept running into information about SEO. I came across an article that discussed how dates affect Google search results (and maybe Yandex too, I’m not sure). That is, the date impacts how “fresh” or relevant a post appears. For example, a post from 2010 is less relevant than one from 2014 on the same topic. Of course, the date isn’t the most important ranking factor, but it still counts — better safe than sorry.

The author (I don’t remember the link) recommended avoiding dates in URLs and also hiding post and comment dates. Because if the post date is missing, search engines might assume the date of the first comment is the post date. Hiding all dates tricks the search engine into thinking the post is still fresh. But I wonder — could this backfire in a couple of years?

I checked a dozen popular WP blogs to study the matter. And guess what? Many do hide their dates. Some remove them completely (which is annoying — how are you supposed to know when the article was written?). Most blogs use URL formats like “/category-name/post-name” or just “/post-name”.

Honestly, I’m not sure if this is coincidence, but I decided to follow suit. And since the article author recommended the “Hide My Dates” plugin, that’s what I used.

I installed the plugin. Viewed a post — nice, no visible date! Turned on Firefox Inspector — no date in the code. I thought: must be JavaScript (turns out it’s CSS — more on that later). Scrolled to the comments — damn! The layout was broken. The plugin was to blame. Here’s a screenshot:

Date breaking the layout

A minor issue, but still unpleasant.

Without going into too much detail — to fix this, we need to edit the title attribute of the time tag in the “twentytwelve_comment” function.

Open /wp-content/themes/twentytwelve/functions.php and locate the function twentytwelve_comment. Find this code:

printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
	esc_url( get_comment_link( $comment->comment_ID ) ),
	get_comment_time( 'c' ),
	sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
);

Replace it with:

printf( '<a href="%1$s"><time>%2$s</time></a>',
	esc_url( get_comment_link( $comment->comment_ID ) ),
	sprintf( __( '%1$s at %2$s', 'wp2fl-ext' ), get_comment_date(), get_comment_time() )
);

After that, the dates display correctly without breaking the layout:

Properly displayed date

That’s it! In the next article, I’ll explain how the “Hide My Dates” plugin works and why this bug occurs.

Posts on similar topics

Are you having problems with your WordPress site? Do you need additional functionality? A custom plugin or a new page?
Then write to me via the feedback form, and I will try to help you.

Write a comment

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