Title: Filter Request | Local Time
Last modified: October 7, 2023

---

# Filter Request | Local Time

 *  Resolved [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/)
 * Great plugin!
 * Hey, is there any way you can provide a filter (i.e., code snippet) that would
   allow us to use the shortcode pattern provide below instead of using (loading)
   your entire plugin?
 * `[wpdts-hour]:[wpdts-minute] [wpdts-am-pm am_pm="u"]`
 * Thank you!

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

 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107712)
 * Hello [@generosus](https://wordpress.org/support/users/generosus/),
   Thank you
   for using our plugin. You can always use your own code snippet, but it might 
   be difficult to achieve other functionalities of the plugin in such cases, if
   they are needed.
 * Here is a sample snippet for shortcode in your special case(s):
 *     ```wp-block-code
       add_shortcode('wpdts_snippet_date_time', 'wpdts_custom_fnc');
       function wpdts_custom_fnc($atts, $content, $tag) {
           $atts_default = [
               'tag'       => 'span',  // The default result tag attribute.
               'format'    => 'G:m A', // The default result tag attribute.
           ];
           $timestamp = current_time('timestamp'); // The current UNIX timestamp according to the time zone.
           // Get the shortcode attributes.
           $atts = shortcode_atts( 
                   $atts_default,
                   $atts,
                   $tag
           );
           $custom_date_time = date_i18n($atts['format'], $timestamp, false);     // The internationalized date and/or time value for the symbols.
           $result = '';                                                           // The result string, which may ot may not be resturned as an HTML tag content.
           if ($atts['tag']) {
               $result .= "<{$atts['tag']} class=\"wpdts-snippet-date-time\">";
           }
           $result .= $custom_date_time;
           if ($atts['tag']) {
               $result .= "</{$atts['tag']}>";
           }
           return $result;
       }
       ```
   
 * You can use the new shortcode like this:
 *     ```wp-block-code
       [wpdts_snippet_date_time format="G:m A"]
       [wpdts_snippet_date_time tag="" format="G:m A"]
       [wpdts_snippet_date_time tag="p" format="Y-m-d H:i:s"]
       ```
   
 * You just need to change the `tag` (for HTML tag, if needed; the default is `<
   span>`) and the `format` attributes (using [the symbols](https://www.php.net/manual/en/datetime.format.php)
   for the `date_i18n` function).
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107721)
 * PS: Surely you can also use the WP Date and Time Shortcode plugin with:
 *     ```wp-block-code
       [wpdts-custom format="G:i A"]
       ```
   
 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107736)
 * Wow! Thanks for the quick reply.
 * Unfortunately, the Local Server Time displayed using your code snippet is not
   accurate.
 * Details: [https://prnt.sc/iqM7omYYXwq2](https://prnt.sc/iqM7omYYXwq2)
 * Can you revisit it once again, and advise?
 * Also, is their a way to modify your code snippet to capture the local time of
   our website visitor(s)?
 * Thank you!
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107747)
 * Hello again,
 * The result does not depend on your server time and server time zone but on your
   WordPress General Settings time zone. There is no feature in the plugin to capture
   the visitor’s time. It is planned for the Pro edition but its release date is
   not fixed.
 * The only time which is used for now is the WordPress General Settings time according
   to the time zone or the time in the time zone set via the `time_zone` attribute
   according to:
   [https://www.php.net/manual/en/timezones.php](https://www.php.net/manual/en/timezones.php)
 * Like this:
 *     ```wp-block-code
       [wpdts-date-time time_zone="Europe/Paris"]
       ```
   
 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107749)
 * Thank you! We look forward to your Pro Version incorporating the above.
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107752)
 * OK. Hopefully the answers above may help you somehow in your case.
 * Good luck!
 *  Plugin Author [Denra.com](https://wordpress.org/support/users/denra/)
 * (@denra)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17107762)
 * PS: I found the bug with the code above. The `format` symbol for minutes is wrong.
   It should be `G:i A` and not `G:m A`. I apologize for the string error.
 *     ```wp-block-code
       $atts_default = [
               'tag'       => 'span',  // The default result tag attribute.
               'format'    => 'G:i A', // The default result format attribute.
           ];
       ```
   
 *  Thread Starter [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17108506)
 * Hey [@denra](https://wordpress.org/support/users/denra/),
 * Works great now, thank you. Still, it would be nice to provide a shortcode to
   display the visitor’s date, time, and timezone (i.e, based on visitor’s server
   location or geolocation). Hopefully, your Pro Version will provide that feature.
 * Cheers!

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

The topic ‘Filter Request | Local Time’ 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

 * [code snippet](https://wordpress.org/support/topic-tag/code-snippet/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [format](https://wordpress.org/support/topic-tag/format/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [symbols](https://wordpress.org/support/topic-tag/symbols/)
 * [time](https://wordpress.org/support/topic-tag/time/)
 * [timestamp](https://wordpress.org/support/topic-tag/timestamp/)

 * 8 replies
 * 2 participants
 * Last reply from: [generosus](https://wordpress.org/support/users/generosus/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/filter-request-local-time/#post-17108506)
 * Status: resolved