Group Posts by Date (year and month)

This ShortCode let’s you “group” posts in a View by their Publish Date, by year and then month.

To use it, add this to functions.php:

add_shortcode('heading', 'my_heading');
function my_heading($atts, $content = '') {
  static $year = null;
  static $month = null;
  $condition = $atts['condition'];
  $value = $atts['value'];
  switch ($condition) {
      case 'year':
      case 'month':
        if ($condition != $value) {
            $condition = $value;
            return $content;
  return '';

Then use this new ShortCode in the Views loop as the below example:

[heading condition="year" value="2016"]
[heading condition="month" value="June"]