Article Published and Modified Date Meta Tags
Adds article:published_time and article:modified_time meta tags to blog posts, which social networks and search engines use to understand how fresh a post is.
Opens WPIDE on
Code
add_action( 'wp_head', function () {
if ( ! is_singular( 'post' ) ) {
return;
}
$post = get_queried_object();
echo '<meta property="article:published_time" content="' . esc_attr( get_post_time( 'c', true, $post ) ) . '" />' . "\n";
echo '<meta property="article:modified_time" content="' . esc_attr( get_post_modified_time( 'c', true, $post ) ) . '" />' . "\n";
foreach ( get_the_category( $post->ID ) as $category ) {
echo '<meta property="article:section" content="' . esc_attr( $category->name ) . '" />' . "\n";
break;
}
}, 6 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.