Add a “Time Since Last Post” Widget to WordPress Dashboard

⏲️ Estimated reading time: 6 min

Keep your blog active! This simple plugin helps you track how much time has passed since your last post was published. Perfect for bloggers who want a gentle nudge to stay consistent.

Creating a custom WordPress plugin might seem overwhelming for beginners, but don’t worry. This guide will walk you through building a simple and useful dashboard widget from scratch: a live timer that shows how much time has passed since your last published post.

⏱ Add a “Time Since Last Post” Widget to WordPress Dashboard

Let’s break it down into steps and explain everything in plain language.


🧩 What This Plugin Does

This custom plugin will:

  • Display the title and publish time of your most recent post.
  • Show a dynamic counter (like a stopwatch) that updates every second.
  • Encourage you to write new content if too much time has passed.

It’s great for staying productive and knowing when your blog needs fresh content.


🛠️ Full Plugin Code

Below is the complete code for the plugin. You’ll learn how it works in the next sections.

<?php 
/**
 * Plugin Name: Time Since Last Post Dashboard Widget
 * Description: Displays how much time has passed since the last blog post was published.
 * Version: 1.0
 * Author: HelpZone
 */

add_action('wp_dashboard_setup', 'hz_elapsed_time_dashboard_widget');

function hz_elapsed_time_dashboard_widget() {
    wp_add_dashboard_widget(
        'hz_elapsed_time_dashboard_widget',
        'Time Since Last Post',
        'hz_elapsed_time_dashboard_widget_content'
    );
}

function hz_elapsed_time_dashboard_widget_content() {
    $last_post = get_posts([
        'numberposts' => 1,
        'post_type'   => 'post',
        'post_status' => 'publish',
        'orderby'     => 'post_date',
        'order'       => 'DESC',
    ]);

    $last_post_time = 0;
    $post_title = 'No posts yet.';
    $post_link = '';

    if (!empty($last_post)) {
        $last_post_obj = $last_post[0];
        $last_post_time = strtotime($last_post_obj->post_date_gmt . ' +0000');
        $post_title = esc_html($last_post_obj->post_title);
        $post_link = get_permalink($last_post_obj->ID);
    }

    $current_gmt_time = current_time('timestamp', true);
    ?>
    <div class="elapsed-time-widget">
        <?php if (!empty($last_post)) : ?>
            <p>Last published post: "<a href="<?php echo $post_link; ?>"><?php echo $post_title; ?></a>"</p>
            <p>Published on: <strong><?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_post_time); ?></strong></p>
            <hr/>
            <h3>Time passed since you published last post:</h3>
            <div id="elapsed-timer" style="font-size: 2em; font-weight: bold; text-align: center; color: #d54e21;">
                <span class="elapsed-display">Calculating...</span>
            </div>
            <p style="text-align: center;">
                <a href="<?php echo admin_url('post-new.php'); ?>" class="button button-primary">Write a new post!</a>
            </p>
        <?php else : ?>
            <p>No posts have been published yet. Once you publish, the timer will start.</p>
            <p style="text-align: center;">
                <a href="<?php echo admin_url('post-new.php'); ?>" class="button button-primary">Publish your first post!</a>
            </p>
        <?php endif; ?>
    </div>

    <script type="text/javascript">
        jQuery(document).ready(function($) {
            var lastPostTime = <?php echo $last_post_time; ?> * 1000;
            var serverNow = <?php echo $current_gmt_time; ?> * 1000;
            var clientStartTime = new Date().getTime();

            function updateElapsedTime() {
                var clientNow = new Date().getTime();
                var estimatedServerNow = serverNow + (clientNow - clientStartTime);
                var elapsed = estimatedServerNow - lastPostTime;

                var days = Math.floor(elapsed / (1000 * 60 * 60 * 24));
                var hours = Math.floor((elapsed % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((elapsed % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((elapsed % (1000 * 60)) / 1000);

                var text = '';
                if (days > 0) {
                    text += String(days).padStart(2, '0') + 'd ';
                }
                text += String(hours).padStart(2, '0') + 'h ';
                text += String(minutes).padStart(2, '0') + 'm ';
                text += String(seconds).padStart(2, '0') + 's ago';

                var display = $('#elapsed-timer .elapsed-display');
                display.text(text);

                if (elapsed >= 24 * 60 * 60 * 1000) {
                    display.css('color', 'green');
                }
            }

            updateElapsedTime();
            setInterval(updateElapsedTime, 1000);
        });
    </script>
    <?php
}
?>
Add a “Time Since Last Post” Widget to WordPress Dashboard

🧰 Step-by-Step: How to Use This Plugin

1. Open Your WordPress Plugin Folder

Use FTP, File Manager in cPanel, or local dev tools and go to:

wp-content/plugins/

2. Create a New Plugin File

Create a file called:

time-since-last-post.php

Paste the full code from above into this file and save.

3. Activate the Plugin

  • Go to your WordPress dashboard
  • Navigate to Plugins → Installed Plugins
  • Find Time Since Last Post Dashboard Widget
  • Click Activate

Done! A new box will now appear in your Dashboard.


🧠 How It Works: Explained for Beginners

add_action('wp_dashboard_setup', ...)

This hook tells WordPress to run a function when setting up the admin dashboard. Our function hz_elapsed_time_dashboard_widget() adds the custom box.

get_posts([...])

This retrieves the most recent published blog post. If you haven’t posted anything yet, it defaults to a message.

JavaScript Timer

The live counter uses jQuery to update the time every second. It also calculates the time based on GMT so it stays accurate, even if your browser time is off.


Add a “Time Since Last Post” Widget to WordPress Dashboard

✅ Bonus Features

  • Automatically turns the timer green when more than 24 hours have passed.
  • Includes a “Write a new post” button right inside the widget.
  • Fully dynamic – no page refresh needed.

🧪 Test It!

You can test the widget by:

  1. Creating and publishing a post.
  2. Visiting your WordPress Dashboard.
  3. Watching the timer increase in real time.
  4. Waiting more than 24 hours to see the color change.

🔄 Customize It

You can easily change:

  • Colors
  • Date format
  • Default messages
  • The position or size of the widget

This is just a starting point – get creative!


📦 Plugin Folder Structure

wp-content/
└── plugins/
    └── time-since-last-post/
        └── time-since-last-post.php

Make sure the file and folder names match!


🚀 Who Is This For?

  • Bloggers who want reminders to post more consistently
  • WordPress beginners exploring dashboard customizations
  • Agencies managing multiple content sites
  • Developers learning to combine PHP + JavaScript in WordPress

🔔For more tutorials like this, consider subscribing to our blog.

📩 Do you have questions or suggestions? Leave a comment or contact us!
🏷️ Tags: WordPress plugins, beginner WordPress, dashboard widget, PHP plugin tutorial, elapsed time, publish tracker, WordPress development, WP tutorial, blog productivity, WP dashboard
📢 Hashtags: #WordPress, #WPPlugin, #WPBeginner, #CustomPlugin, #WordPressDev, #DashboardWidget, #TimeTracker, #BlogTools, #CodingForBeginners, #HelpZoneTips


Final Thoughts

Adding custom features to your WordPress dashboard doesn’t have to be intimidating. With a simple plugin like this, you can track your publishing frequency and stay consistent without third-party tools. Keep building useful tools like this and you’ll quickly grow more confident with WordPress plugin development.

Report an issue (max 5 words):

We store the message, post link, time, and IP (for abuse prevention). No account required.

Want to support us? Let friends in on the secret and share your favorite post!

0 online now

Live Referrers

Photo of author

Flo

Add a “Time Since Last Post” Widget to WordPress Dashboard

Published

Update

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! 🚀

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.