Skip to content

Instantly share code, notes, and snippets.

@jeherve
Created May 11, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeherve/0fa52b03555b939478253e8124eb01e5 to your computer and use it in GitHub Desktop.
Save jeherve/0fa52b03555b939478253e8124eb01e5 to your computer and use it in GitHub Desktop.
Jetpack's Top Posts Widget: add post date and post author below each post.
<?php
/**
* Plugin Name: Top Posts Widget: add post date and post author below each post.
* Plugin URI: http://jeremy.hu
* Description: Top Posts Widget: add post date and post author below each post.
* Version: 1.0
* Author: Jeremy Herve
* Author URI: http://jeremy.hu
* Text Domain: jeherve
* Domain Path: /languages/
* License: GPL2
*/
function jeherve_add_date_author_top_posts( $post_id ) {
$post_date = get_post_time(
get_option( 'date_format' ),
true,
$post_id,
true
);
$post_author = get_post_field( 'post_author', $post_id );
$post_author_name = get_the_author_meta( 'display_name', $post_author );
printf(
'On <span class="top_posts_date">%1$s</span>, by <span class="top_posts_author">%2$s</span>',
$post_date,
$post_author_name
);
}
add_action( 'jetpack_widget_top_posts_after_post', 'jeherve_add_date_author_top_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment