Home / Heartbeat Setting
Duplicate Snippet

Embed Snippet on Your Site

Heartbeat Setting

Add a setting that allows you to configure the heartbeat interval.

10+
Code Preview
php
<?php
// Add a new setting in wp-admin > Settings > General
add_action( 'admin_init', function() {
   register_setting( 'general', 'custom_heartbeat_interval', 'intval' );
   add_settings_field( 'custom_heartbeat_interval', 'Heartbeat Interval', function() {
       $interval = get_option( 'custom_heartbeat_interval', 120 );
       echo "<input type='number' name='custom_heartbeat_interval' value='".absint($interval)."' min='15' max='120' /> seconds";
   }, 'general' );
});
add_filter( 'heartbeat_settings', function( $settings ) {
   $settings['interval'] = get_option( 'custom_heartbeat_interval', 120 );
   return $settings;
});

Comments

Add a Comment