Created
May 11, 2016 16:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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