Skip to content

Instantly share code, notes, and snippets.

@JoshuaDoshua
Forked from petertwise/addtogcal.php
Last active August 3, 2018 13:32
Show Gist options
  • Save JoshuaDoshua/26ae2e34f6472db32f139ae4a4519fd4 to your computer and use it in GitHub Desktop.
Save JoshuaDoshua/26ae2e34f6472db32f139ae4a4519fd4 to your computer and use it in GitHub Desktop.
Function to create Add to Google Calendar link
<?php
function squarecandy_add_to_gcal(
$name,
$startDate,
$endDate = false,
$isAllDay = false,
$description = null,
$location = null
) {
$shortFormat = "Ymd";
$longFormat = "Ymd\THis";
$startDate = strtotime($startDate);
$endDate = strtotime($endDate);
$startDate = $isAllDay
? date($shortFormat, $startDate)
: date($longFormat, $startDate);
$endDate = $isAllDay
? date($shortFormat, $endDate)
: date($longFormat, $endDate);
$url = 'http://www.google.com/calendar/event?';
$url .= http_build_query([
'action' => 'TEMPLATE',
'dates' => $startdate . '/' . $enddate,
'details' => $description,
'location' => $location
]);
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment