Make a Timestamp Shortcode

epoch-time-pluginThis snippet creates a shortcode to display the Unix Epoch time. Most likely reason you might use this plugin is to create DoubleClick cache busting links.

I wrote a WordPress plugin for this same purpose. The plugin contains the same code snippet. It is up to you whether you add this snippet to functions.php or use the plugin. The plugin version of this shortcode is here.

Instructions for adding this snippet to WordPress are here.

The shortcode this code creates is [[timestamp]]. Place that shortcode anywhere within a page or widget to display the timestamp.

To use in DoubleClick links (or any other links that require a timestamp), put the shortcode in the link wherever the timestamp needs to display.

For example:

To display the Unix timestamp in a DoubleClick link, put the shortcode after the “ord=” attribute like this “ord=[[timestamp]]” which will create “ord=[timestamp]” (refresh the page to see a different number).

The shortcode code

Add the shortcode to WordPress by putting this snippet into your child theme’s functions.php file.

// Do TimeStamper Shortcode ( timestamper() )

function timestamper( $atts ){
  if (!is_admin()) {
    add_filter('widget_text', 'do_shortcode', 11);
  }
  $time = current_time( 'timestamp' );
  return $time;
}
add_shortcode( 'timestamp', 'timestamper' );

Sharing is caring!

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x