Skip to content

Instantly share code, notes, and snippets.

@jocastaneda
Created June 5, 2017 23:02
Show Gist options
  • Save jocastaneda/881776acd2b10b9067bd0317562483c5 to your computer and use it in GitHub Desktop.
Save jocastaneda/881776acd2b10b9067bd0317562483c5 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Kalunder
Plugin URI: http://blog.josemcastaneda.comn
Description: Adds the shortcode kalunder so that you can display the WordPress calendar to any post, page or custom post type.
Author: Jose Castaneda
Version: 1.0.0
Author URI: https://blog.josemcastaneda.com
*/
add_shortcode( 'kalunder', 'jc_get_cal' );
function jc_get_cal( $atts ) {
// set a unique ID for the calendar.
$id = uniqid( 'wp-calendar-' );
//get the calendar.
$cal = get_calendar( false, false );
// replace the ID.
$cal = str_replace( 'id="wp-calendar"', 'id="' . $id . '"', $cal );
// Set a wrapper.
$out = sprintf( '<div class="calendar_wrap" id="calendar-%1$s">%2$s</div>',
get_the_ID(),
$cal
);
// finally return it.
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment