Skip to main content
Login Join
Snippet · PHP

Automatically Add Estimated Reading Progress Bar

Shared by Amit Dholiya · August 3, 2026 · @wp_footer

11 views
1 upvote
Back to Snippets

Enhance the reading experience by displaying a progress bar at the top of your website that fills as visitors scroll through a post. This feature is commonly found on news, blog, and documentation websites.

Steps

  1. Open your active theme’s functions.php file or a custom functionality plugin.
  2. Add the code below.
  3. Save the file.
  4. Open any single post and start scrolling to see the reading progress bar.

Benefits

/**
 * Display a reading progress bar on single posts.
 */
function wpfolks_reading_progress_bar() {

    if ( ! is_singular( 'post' ) ) {
        return;
    }
    ?>
    <style>
        #wpfolks-reading-progress{
            position:fixed;
            top:0;
            left:0;
            width:0;
            height:4px;
            background:#0073aa;
            z-index:999999;
            transition:width .1s linear;
        }
    </style>

    <div id="wpfolks-reading-progress"></div>

    <script>
    document.addEventListener('scroll', function () {
        const scrollTop = window.scrollY;
        const docHeight = document.documentElement.scrollHeight - window.innerHeight;
        const progress = (scrollTop / docHeight) * 100;

        document.getElementById('wpfolks-reading-progress').style.width = progress + '%';
    });
    </script>
    <?php
}
add_action( 'wp_footer', 'wpfolks_reading_progress_bar' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments