• Resolved Generosus

    (@generosus)


    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

    (@denra)

    Hello @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):

    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:

    [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 for the date_i18n function).

    Plugin Author Denra.com

    (@denra)

    PS: Surely you can also use the WP Date and Time Shortcode plugin with:

    [wpdts-custom format="G:i A"]
    Thread Starter Generosus

    (@generosus)

    Wow! Thanks for the quick reply.

    Unfortunately, the Local Server Time displayed using your code snippet is not accurate.

    Details: 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

    (@denra)

    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

    Like this:

    [wpdts-date-time time_zone="Europe/Paris"]
    Thread Starter Generosus

    (@generosus)

    Thank you! We look forward to your Pro Version incorporating the above.

    Plugin Author Denra.com

    (@denra)

    OK. Hopefully the answers above may help you somehow in your case.

    Good luck!

    Plugin Author Denra.com

    (@denra)

    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.

    $atts_default = [
            'tag'       => 'span',  // The default result tag attribute.
            'format'    => 'G:i A', // The default result format attribute.
        ];
    Thread Starter Generosus

    (@generosus)

    Hey @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.