Title: Edit the plugin code snippet
Last modified: October 30, 2022

---

# Edit the plugin code snippet

 *  Resolved [chris15326](https://wordpress.org/support/users/chris15326/)
 * (@chris15326)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/)
 * Hey! I just wonder if there is a way to change / edit the plugins code that it
   adds (to the function.php?) in order to grab the current time + add something
   like 30 minutes in 15 minute intervals.
 * So that the result will always be XX:00 XX:15 XX:30 XX:45 while using 24h format.
 * For example: if it’s 09:10 it would show 09:30 or 09:45.
 * With kind regards
    Chris

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/#post-16147226)
 * Hi [@chris15326](https://wordpress.org/support/users/chris15326/),
 * Let me think about a custom solution. I will write back soon (in a couple of 
   days).
 * Regards,
    Ivaylo Tinchev Denra.com
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/#post-16150891)
 * Hello again [@chris15326](https://wordpress.org/support/users/chris15326/) ,
 * Please place the code below in the functions.php of your child theme:
 *     ```
       add_shortcode( 'wpdts-custom-intervals', 'wpdts_custom_intervals' );
       function wpdts_custom_intervals( $atts_set, $content, $tag ) {
           // Default attributes for the shortcode.
           $atts_default = array(
               'start'     => current_time( 'mysql', false ), // The time to show.
               'format'    => 'M j, Y G:i',  // The final format with PHP date() symbols.
               'intervals' => '00,15,30,45', // In minutes of the hour.
           );
           // All final attributes.
           $atts = shortcode_atts( 
               $atts_default,
               $atts_set,
               $tag
           );
           // The current timestamp according to the 'start' attribute.
           $ts_start = intval( strtotime( $atts['start'] ) );
           // Timestamp still not rounded.
           $ts_final = $ts_start; 
           // Convert the interval attribute values to an array of integers.
           $intervals_arr = explode( ',', $atts['intervals'] );
           if ( count( $intervals_arr ) ) { // In case we have intervals set we search.
               // Convert the intervals minitues strings to timestamps.
               $ts_intervals_arr = array();
               foreach( $intervals_arr as $value ) {
                   // In case we have 0 or passed minutes then switch to next hour.
                   $ts_modified = ( 0 == $value || date( "i", $ts_start ) >= $value ) ? $ts_start + HOUR_IN_SECONDS : $ts_start;
                   // Calculate the intervals timestamps.
                   $ts_intervals_arr[] = strtotime( date( "Y-m-d H:" . sprintf( '%02d', $value ) . ":00", $ts_modified ) );
               }
               // Sort the intervals array in reverse order.
               rsort( $ts_intervals_arr );
               // Let us keep the previous interval timestamp value.
               $ts_interval_prev = array_shift( $ts_intervals_arr );
               foreach( $ts_intervals_arr as $ts_interval ) {
                   if ( $ts_start >= $ts_interval  ) {
                       //The closest interval timestamp is found.
                       break;
                   }
                   else {
                       // Keep the closer interval timestamp.
                       $ts_interval_prev = $ts_interval;
                   }
               }
               $ts_final = $ts_interval_prev;
           }
           return date( $atts['format'], $ts_final );
       }
       ```
   
 * Then try it with the following shortcode:
    `[wpdts-custom-intervals]`.
 * You can also use custom `format` and `intervals` attributes instead of the default
   ones like this:
    `[wpdts-custom-intervals format="Y-m-d H:i:s" intervals="00,30"]`.
 * Please let me know if it works for you.
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/#post-16158526)
 * Hello [@chris15326](https://wordpress.org/support/users/chris15326/),
 * I am closing the support thread. Please reopen it again if needed.
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/#post-16158529)
 * Closed.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Edit the plugin code snippet’ is closed to new replies.

 * ![](https://ps.w.org/wp-date-and-time-shortcode/assets/icon.svg?rev=2291661)
 * [WP Date and Time Shortcode](https://wordpress.org/plugins/wp-date-and-time-shortcode/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-date-and-time-shortcode/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-date-and-time-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-date-and-time-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-date-and-time-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-date-and-time-shortcode/reviews/)

## Tags

 * [current time](https://wordpress.org/support/topic-tag/current-time/)
 * [hour](https://wordpress.org/support/topic-tag/hour/)
 * [interval](https://wordpress.org/support/topic-tag/interval/)
 * [minutes](https://wordpress.org/support/topic-tag/minutes/)
 * [result](https://wordpress.org/support/topic-tag/result/)
 * [rounded](https://wordpress.org/support/topic-tag/rounded/)

 * 4 replies
 * 2 participants
 * Last reply from: [Denra.com](https://wordpress.org/support/users/denra/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/edit-the-plugin-code-snippet/#post-16158529)
 * Status: resolved