Create .ics calendar files from WordPress posts & custom post types

For websites that feature events, either through plugin or custom post type, it might be important to allow user to download individual.ics calendar files.
ICS files can be opened in pretty much any calendar management app or software, like Outlook, Google Calendar and iCalendar.
Often, plugins provide the .ics generation functionality built-in, other times they require that you purchase an add-on… now you can do it yourself!

Copy and paste this script in your theme’s functions.php file and edit the parts that you need to customize:

Make sure that you read carefully through the code, especially the part with the date vars, location, organizer etc. so that your events are fully represented in the users’ calendar.

I personally like to use Types, to manage custom post types, custom taxonomies and custom fields, so a practical example in that case would be:

$start_date = date_i18n("Ymd\THis\Z", get_post_meta( get_the_ID(), 'wpcf-start_date', true ));
$end_date = date_i18n('Ymd\THis\Z', get_post_meta( get_the_ID(), 'wpcf-end_date', true));
$deadline = date_i18n('Ymd\THis\Z', get_post_meta( get_the_ID(), 'wpcf-deadline_date', true)-24, true);
$location = types_render_field("location", array('output' => 'raw'));
$city = types_render_field("city", array('output' => 'raw'));
$street = types_render_field("street", array('output' => 'raw'));
$address = $location.' - '.$street.', '.$city;

Media Temple Hosting

So, once looping through your posts, all you have to add is a link or button to the custom endpoint, carrying the post ID in the url parameter, like this:

<a href="<?php echo get_feed_link('calendar'); ?>?id=<?php echo get_the_ID(); ?>"> Download .ics </a>

The user will then be able to download and open the .ics file in whatever calendar app / software they want.

Now, why not pairing this cool feature with a handy weekly calendar for WordPress?

Jany Martelli

I’m a Digital Consultant, Front-End Developer, specialized in WordPress.
I help companies, professionals and startups grow with technology and a winning digital strategy, I hand-pick and coordinate the perfect team for them, plan projects from the ground-up, develop & deploy websites, online stores and apps.

Privacy Preference Center


Also called a transient cookie, a cookie that is erased when the user closes the Web browser. The session cookie is stored in temporary memory and is not retained after the browser is closed. Session cookies do not collect information from the user s computer.

They are usually used to temporarily keep track of users' preferences (eg. currency, language, items you place in the cart - in case of an e-commerce website, which this website is not) throughout the website. Other times they are used to make sure the user is not a malicious bot trying to take down a website, hence the cookie cannot be disabled for security reasons.

They are usually harmless (or they should be!) and will go away when you leave the website or close the browser.



Persistent Cookies.

Also called a permanent cookie, or a stored cookie, a cookie that is stored on a user's hard drive, until it expires (persistent cookies are set with expiration dates) or until the user deletes the cookie.

These cookies are meant to profile the website's visitors and let the admins know who visits their website. Your name is NOT tracked, but your IP, country, browser and device specs, research terms and more, usually is. It helps admins understand what contents their users like best and who is their audience, in order to provide better and more targeted content.

Other cookies have the same functions as session ones: for example, they simply help the browser remember if your Internet connection is fast enough to play high-quality videos next time, or what language you chose for your subtitles.

Some of these might be relatively harmelss, since they were meant to first and foremost help admins to manage their site's audience and content, however they might also be used, to be collected and sold to third parties.

You can check a full explanation of a few of the most common ones here



Persistent Cookies.

Also called a permanent cookie, or a stored cookie, a cookie that is stored on a user's hard drive, until it expires (persistent cookies are set with expiration dates) or until the user deletes the cookie.

These cookies are meant to collect your browsing preferences (your searches, the websites you visit, things you like or don't like, personal conditions and things you might not want a third party to know about nor to be sold to someone else).

A vast majority of websites, search engines, apps and social networks, will place these cookies in your browsers because they are showing you ads and making money off them. This is not inherently bad, however the ad you see, comes also with these cookies, to help Advertising Networks to show you even more relevant ads, as well as collect a vast amount of data about Internet users, to then be sold or mishandled in ways that could harm society.

This website shows Ads from Google, therefore it places their cookies in your browser (sorry!).
If you don't wish to be tracked, please adjust your privacy settings here.
We also show Facebook Ads, therefore if you don't wish to be tracked by them, please head over here to change your settings.

Also turn these cookies' consent toggle OFF.

Please understand that not allowing Advertising cookies to be placed in your browser, does NOT mean you will not see ads, you STILL will, but they simply will not be relevant to your own interests anymore.

On Chrome, click here, to block all third party cookies (they might all be used for advertising or collect your preference to be sold to the highest bidder, though, but most likely they will be).

If you want to have even more control over which third parties can collect your data (even outside this website), please visit this website.