do_action ( 'jetpack_widget_top_posts_before_post', string $post[’post_id’] )

Fires before each Top Post result, inside <li>.

Source file: modules/widgets/top-posts.php

View in GitHub

Parameters

$post[’post_id’]

(string) Post ID.


Changelog

Since: Jetpack 3.2.0


Notes

You can use this action to add data before each post in the widget. In the example below, we’ll insert the post date above each post:

function jetpackme_add_date_top_posts( $post_id ) {
        $post_date = get_post_time(
                get_option( 'date_format' ),
                true,
                $post_id,
                true
        );
        printf( '<div class="top_posts_date">%s</div>', $post_date );
}
add_action( 'jetpack_widget_top_posts_before_post', 'jetpackme_add_date_top_posts' );

Have a question?

Comments are closed for this article, but we're still here to help! Visit the support forum and we'll be happy to answer any questions.

View support forum