Skip Navigation

[Resolved] Trying to display the current month

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to display the current month inside a View.

Solution: There's no built-in way to display the current date. Add this code to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom Code:

add_shortcode( 'ts_format_date_intl', 'ts_format_date_intl_func');
function ts_format_date_intl_func( $atts, $content ) {
  $a = shortcode_atts( array(
      'format' => '%c',
      'timestamp' => time()
  ), $atts );
 
  return strftime( $a['format'], $a['timestamp'] );
}

Then you can display the current month by adding this shortcode:

[ts_format_date_intl format="%B"]

Relevant Documentation:
http://php.net/manual/en/function.strftime.php

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by jasonw-2 2 years, 6 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#1140436

Hi there,

Could you please help me. I am trying to display the current month within a view. So if the current month is November, I'd like to be able to display that. I just can't seem to figure it out.

Thanks as always. You all are the best. 🙂

#1140725

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

There's no built-in way to do this in WordPress or Toolset. I have a custom shortcode that can help, it's a proxy to PHP strftime(). Add this code to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom Code:

add_shortcode( 'ts_format_date_intl', 'ts_format_date_intl_func');
function ts_format_date_intl_func( $atts, $content ) {
  $a = shortcode_atts( array(
      'format' => '%c',
      'timestamp' => time()
  ), $atts );

  return strftime( $a['format'], $a['timestamp'] );
}

Then you can display the current month by adding this shortcode:

[ts_format_date_intl format="%B"]

More information about the different date formats available here:
http://php.net/manual/en/function.strftime.php

#1142390

You are the man. THANK YOU so much. 🙂