# Site Activity Timeline Widget

> Adds a dashboard widget with one timeline of the latest published posts, approved comments and new user sign-ups, newest first, so you see what happened on the site at a glance.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard-widget, activity, timeline
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dash-activity-timeline-widget/

## Code

```php
// Number of events to show.
$wpide_timeline_count = 12;

add_action( 'wp_dashboard_setup', function () use ( $wpide_timeline_count ) {
    wp_add_dashboard_widget( 'wpide_activity_timeline', 'Activity timeline', function () use ( $wpide_timeline_count ) {
        $events = array();

        foreach ( get_posts( array( 'post_type' => array( 'post', 'page' ), 'posts_per_page' => $wpide_timeline_count, 'no_found_rows' => true ) ) as $post ) {
            $events[] = array( get_post_time( 'U', true, $post ), 'dashicons-edit', sprintf( 'Published <a href="%s">%s</a>', esc_url( get_edit_post_link( $post ) ), esc_html( get_the_title( $post ) ) ) );
        }
        foreach ( get_comments( array( 'status' => 'approve', 'number' => $wpide_timeline_count, 'type' => 'comment' ) ) as $comment ) {
            $events[] = array( strtotime( $comment->comment_date_gmt . ' UTC' ), 'dashicons-admin-comments', sprintf( '%s commented on <a href="%s">%s</a>', esc_html( $comment->comment_author ), esc_url( get_comment_link( $comment ) ), esc_html( get_the_title( $comment->comment_post_ID ) ) ) );
        }
        if ( current_user_can( 'list_users' ) ) {
            foreach ( get_users( array( 'number' => $wpide_timeline_count, 'orderby' => 'registered', 'order' => 'DESC' ) ) as $user ) {
                $events[] = array( strtotime( $user->user_registered . ' UTC' ), 'dashicons-admin-users', sprintf( '<a href="%s">%s</a> signed up', esc_url( get_edit_user_link( $user->ID ) ), esc_html( $user->display_name ) ) );
            }
        }

        usort( $events, function ( $a, $b ) {
            return $b[0] <=> $a[0];
        } );

        if ( ! $events ) {
            echo '<p>No activity yet.</p>';
            return;
        }

        echo '<ul style="margin:0">';
        foreach ( array_slice( $events, 0, $wpide_timeline_count ) as $event ) {
            printf(
                '<li style="display:flex;gap:8px;align-items:flex-start;padding:6px 0;border-bottom:1px solid #f0f0f1"><span class="dashicons %s" style="color:#787c82" aria-hidden="true"></span><span style="flex:1">%s<br><small style="color:#646970">%s ago</small></span></li>',
                esc_attr( $event[1] ),
                $event[2],
                esc_html( human_time_diff( $event[0] ) )
            );
        }
        echo '</ul>';
    } );
} );
```

## Notes

Shows the last 12 events; change $wpide_timeline_count. New users only appear for people who can list users.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Site Activity Timeline Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
