Archived topic
Remove dateModified from HTML
7 replies · Started by Chris on November 29, 2019
Hi,
Is it possible to remove Modified Date from the HTML, rather than just hiding it with CSS?
You don't want the modified date at all? If not, try this PHP:
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}, 10, 2 );
Let me know :)
Hi Tom,
Thanks for this but it doesn't seem to have worked. I can still see the date in the html, with display: none; set. I have edited my initial post to show the URL
Out of interest, why do you hide it with CSS rather than remove it with PHP when a user has opted not to include it in the GP settings? :)
Are you already using a function to alter the post meta/date? Your HTML on the site doesn't reflect the function I mentioned above.
The GP setting to remove the date should fully remove the date from the HTML.
Let me know :)
Ah yes you were correct, I had some more code in there so I have now combined the two.
Also, apologies as I was mistaken about the setting to remove the date.
I had misremembered and thought there were separate options to show Date Published and Date Modified, but there is only a single option to control the date being shown.
My concern with hiding things via CSS is that it can look deceptive from an SEO point of view. I don't think that is an issue here, but I prefer to just remove it if it is not being used.
In most cases, Google knows whether you're being deceptive or not.
Did you get the above function working now?
Let me know :)
Yes I did, thank you.
Awesome, no problem :)