Init Reading Position – Automatically resume where readers left off

Phiên bản: 1.0 English version

Init Reading Position – Automatically resume where readers left off
Init Reading Position is a WordPress plugin that helps readers return to exactly where they left off in a post. As users scroll through a post, the plugin remembers their position and automatically scrolls back to that point when they revisit — whether logged in or not. It’s ultra-lightweight, jQuery-free, and uses pure JavaScript and REST API for logged-in users.

Main Features

  • Remembers reading position using localStorage for guests.
  • Saves reading position to user_meta per device for logged-in users (PC, Mobile, Tablet…).
  • Automatically scrolls back to the last read position on reload or return.
  • Choose which post types are enabled via settings panel.
  • No tables, no tracking, no bloat – fully clean and safe.
  • No jQuery used, written in modern Vanilla JS.
  • Supports init_rp_delay filter to customize debounce delay before saving.

For both guests and logged-in users

  • Guests’ reading positions are saved via browser localStorage.
  • Logged-in users’ positions are saved in user_meta per post and per device, ensuring each device remembers its own state.

Easy Customization

  • You can choose which post types enable the reading position feature.
  • Supports filters for developers to modify saving delay or logic based on post ID.

Quick Setup

  1. Download the plugin and extract it into /wp-content/plugins/
  2. Activate it via the Plugins menu in WP admin
  3. Configure supported post types in Settings → Reading Position
  4. Done – it runs automatically, no shortcode or block needed.

Performance & Compatibility

  • Compatible with WordPress 5.5 and above
  • Tested on the latest version 6.8
  • Requires PHP 7.4+
  • Theme-independent – works with any modern theme
  • Highly optimized code, no slowdown even on long posts

For Developers

  • Filter init_rp_delay to customize debounce time
  • Filter init_rp_meta_key to change the meta key name
  • Filter init_rp_data_to_store to modify saved content
  • Filter init_rp_should_delete to decide whether to delete saved position
  • Filter init_rp_localized_data to inject extra data into frontend JS

Examples using advanced filters:

// Change debounce time (default: 1000ms)
add_filter('init_rp_delay', fn() => 2000); // 2 seconds

// Customize meta_key used for storing position
add_filter('init_rp_meta_key', function ($key, $post_id, $device) {
    return "_custom_rp_{$post_id}_{$device}"; // Example: _custom_rp_123_PC
}, 10, 3);

// Modify data stored to user_meta (default includes scrollTop, percent, screenHeight, updated)
add_filter('init_rp_data_to_store', function ($data, $post_id, $device, $user_id) {
    $data['ip'] = $_SERVER['REMOTE_ADDR'] ?? ''; // Optionally store user IP
    return $data;
}, 10, 4);

// Prevent deletion of saved position when user reaches end
add_filter('init_rp_should_delete', fn($yes) => false); // Keep it for next session

// Inject debug mode into JS
add_filter('init_rp_localized_data', function ($data, $post_id) {
    $data['debug'] = current_user_can('manage_options'); // Add debug flag for admins
    return $data;
});

Get Started

Whether you’re running a blog, novel site, magazine or long-form content hub, Init Reading Position delivers a smooth and smart reading experience – lightweight, intelligent, and fully automatic.

Changelog

  • 1.0 – First release of Init Reading Position
    • Remembers reading position and resumes when user revisits a post.
    • Stores using localStorage for guests, user_meta for logged-in users — per device.
    • Preloads position from user_meta to avoid redundant REST calls.
    • Deletes saved position when user reaches end of the post.
    • Settings panel to control which post types are enabled.
    • Written in clean Vanilla JavaScript – no jQuery used.
    • No custom DB tables or interference with other plugins.
    • Includes filters: init_rp_delay, init_rp_meta_key, init_rp_data_to_store, init_rp_should_delete, init_rp_localized_data.
    • Lightweight, extendable, and ideal for long-form UX.
Made with in HCMC.

Bình luận


  • Không có bình luận.