Title: [Plugin: Events] ICS Link?
Last modified: August 20, 2016

---

# [Plugin: Events] ICS Link?

 *  [Paulsche](https://wordpress.org/support/users/paulsche/)
 * (@paulsche)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-events-ics-link/)
 * is there a possibility to add a link in the events list that users can click 
   on to download an [.ICS](http://en.wikipedia.org/wiki/ICalendar#Core_object) 
   File?
 * [http://wordpress.org/extend/plugins/wp-events/](http://wordpress.org/extend/plugins/wp-events/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [blakesoft](https://wordpress.org/support/users/blakesoft/)
 * (@blakesoft)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-events-ics-link/#post-2792849)
 * I did it by creating a link with a reference that calls a template which outputs
   the correct headers and text.
 * Happy to share it so let me know if you want the code or more details.
 *  Thread Starter [Paulsche](https://wordpress.org/support/users/paulsche/)
 * (@paulsche)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-events-ics-link/#post-2792850)
 * thanks for posting – yes, i am very interested in the code
 *  [blakesoft](https://wordpress.org/support/users/blakesoft/)
 * (@blakesoft)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-events-ics-link/#post-2792851)
 * OK, I’ll post it here (if it should go somewhere else on the site, let me know
   and I’ll move it).
 * 1. Add a template to your theme which looks like this:
 *     ```
       <?php
       /**
        * Template Name: iCal
        *
        * Custom page template to send iCal vcs content for an event.
        *
        * pw - Summer 2011
        *
        * Notes
        * 1. This template does not output any html at all, but just sends a vcs file.
        * 2. The template reads the event id from the url which calls it: ".../page?id=n" and
        *    must be strict in validating the id because it is used in an sql statement.
        * 3. Uses iCal not vCal format - should be compatible with most Calendars, and can
        *    have 'floating' times instead of UTC only.
        */
        global $wpdb;
        $_id = mysql_real_escape_string($_GET['id']);
        if (is_numeric($_id)) {
           $_event = $wpdb->get_row("SELECT * FROM <code>&quot;.$wpdb->prefix.&quot;events</code> WHERE <code>id</code> = $_id");
           }
       if ($_event->title) {
           $dateStart = date('Ymd\THis', $_event->thetime);
           $dateEnd = date('Ymd\THis', $_event->theend);
           $title = $_event->title;
           $location = $_event->location;
       } else {
           $dateStart = '';
           $dateEnd = '';
           $title = 'No event found';
           $location = '';
           }
       header('Content-type: text/calendar; charset=ISO-8859-1');
       header('Content-Disposition: inline; filename="outlook.vcs"');
       $_feed ="BEGIN:VCALENDAR\n";
       $_feed.="VERSION:2.0\n";
       $_feed.="BEGIN:VEVENT\n";
       $_feed.="DTStart:$dateStart\n";
       $_feed.="DTEnd:$dateEnd\n";
       $_feed.="SUMMARY:$title\n";
       $_feed.="Location:$location\n";
       $_feed.="UID:".$_id."@example.com\n";
       $_feed.="End:VEVENT\n";
       $_feed.="End:VCALENDAR";
       echo $_feed;
       ?>
       ```
   
 * Note – you may want to change the UID to include the time or something to make
   it more unique.
 * 2. Create a new page in your site – it needn’t have any content. Make it Private,
   and under Attributes / Template, choose the iCal template in 1 above.
 * 3. Create a link in the page which displays the event (I don’t use widgets) which
   looks like this:
    `<a href="yoursite/page?id=nn">ICAL</a>` where ‘yoursite/page’
   is a full link to the page you created in 2, and ‘nn’ is the id which identifies
   the event. I modified the ‘events_build_output’ function to put this in.
 * That’s it – but note this will likely make your version of WP-Events incompatible
   and will break if you use the plug-in update system!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: Events] ICS Link?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-events_f2f0f1.svg)
 * [Events](https://wordpress.org/plugins/wp-events/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-events/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-events/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-events/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-events/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-events/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [blakesoft](https://wordpress.org/support/users/blakesoft/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-events-ics-link/#post-2792851)
 * Status: not resolved