21 June 2008 - 9:40pmGoogle Calendar Feed Parser

, , , , ,

Update: Version 0.2 was released today (4/19/2009) which allows configuration of a timezone offset that can be customized to force start and end times from the XML feed to be displayed in the desired timezone (see documentation of the option below).

Update: I’ve added a screenshot of the plugin in action on a blog I administer.  You can view it here.

Google Calendar Feed Parser is a WordPress Plugin designed to facilitate incorporating a Google Calendar XML feed into your WordPress blog.  I wrote this plugin after being unable to find an existing plugin to provide similar functionality.  I intend to keep this plugin up to date, compatible with the most recent releases of WordPress, as they occur.  If you have suggestions, comments, advice, etc. or you would like to help me develop the plugin, feel free to leave a comment and I’ll get back to you.  Any help is appreciated (especially since this is my first WordPress Plugin).  Please let me know if you have any timezone related issues, I had some odd problems getting the times to appear properly.

To install Google Calendar Feed Parser:

  1. Download the zip archive and extract it to the wp-content/plugins directory.
  2. Go to the “Plugins” page in the WordPress Admin interface and click the “Activate” link for the Google Calendar Feed Parser.

To configure Google Calendar Feed Parser:

  1. Go to the “Settings” page in the WordPress Admin interface and click the link for the “Google Calendar” page.
  2. Set the URL for the calendar feed and other settings as desired (see below for full explanation of all options).


  1. Feed URL: This is the URL of the feed you wish to incorporate in your blog.  It should be of the form:


    • For a listing of available parameters, see the Google Calendar API documentation. I found the following query string to provide desirable results:


    • Note that the max-results parameter should not be specified here as it will be handled by the setting below.
  2. Static URL: Use this option if you want to have each event link to a single URL (e.g. have each event link to a page where you’ve embedded your Google Calendar).  If you leave this set to “No”, the plugin will use the link provided by the feed for each individual event.
  3. Max Results: Use this to set the maximum number of events to retrieve and display from the calendar.  If left blank, the plugin’s default is 4.
  4. Timezone Offset: Change this value only if you are having issues with times from the feed displaying correctly. The value supplied in this field is a number of seconds added directly to both the start time and the end time for each event. The default for this value, if left blank, is 7200 seconds. Note: In a future release of the plugin, this option will be replaced with a more comprehensive timezone customization feature.

To Use Google Calendar Feed Parser:

  1. Include a call to the function gcal_parse_feed() at the spot where you want the feed to appear.  I use the feed in my sidebar but you could use the feed wherever you want.
  2. Include style rules in your template’s stylesheet to customize the look of the feed.  A single event outputted from the plugin would be of the form:

    <div id=”events”> <div class=”event”> <h3><a href=”http://some-link-here”>Event Title</a></h3> <p id=”event_time”>July 12, 2009 from 9:00pm to 10:00pm</p> </div> …more events here… </div>


If you like this plugin, please consider donating.


Version 0.1 (first):

  • Ability to set feed URL.
  • Choice of whether to use event URL from feed or static URL for each event.
  • Ability to set max-results parameter.

Future Functionality:

  • Ability to customize query string from the Admin interface in WordPress.

90 Comments | Categories: COSI, General, Technology


  1. Followed the instructions, set up the feed, and I get the following right out of the box:

    Warning: SimpleXMLElement::__construct() [simplexmlelement.–construct]: Entity: line 1: parser error : Start tag expected, ‘<‘ not found in /home/bjhelms/public_html/wp-content/plugins/gcalpars/gcalparse.php on line 104

    Warning: SimpleXMLElement::__construct() [simplexmlelement.–construct]: Unknown projection:basic&max-results=4 in /home/bjhelms/public_html/wp-content/plugins/gcalpars/gcalparse.php on line 104

  2. Justin says;
    02 May 2009 - 11:26pm |

    Everyone, thanks for being diligent in reporting the errors to me. Unfortunately, I haven’t been able to recreate the problem in my own tests (yet). I have some time this week and will try to figure out what’s causing this.

    @John: It seems that what you tried to post didn’t quite work. If you think you’ve found something that fixes this issue, please email me and let me know.

    Thank you all for your patience and I apologize for the trouble this upgrade has caused you all. Please bear with me while I attempt to find and solve the problem.

  3. Justin says;
    02 May 2009 - 11:28pm |

    bjh, it looks to me that something might be wrong with the URL you have set for your calendar’s XML feed. Double-check that and then make sure that you can visit the same URL in your browser properly. If you’re still having trouble, please let me know.

  4. Can you update your instructions to state exactly how to build the URL that should go into settings? I tried going into the settings for the calendar and simply getting the HTML link, and that doesn’t appear to work.

    It looks like a cool plugin, and I’m looking forward to using it.

    Thanks for the help.

  5. Lucas says;
    14 May 2009 - 1:21pm |

    Hey Justin, great plugin! There is any way to add the gcal_parse_feed() method call on a page? I just want to show my calendar on a page, without editing template files. Thanks

  6. matthew says;
    15 May 2009 - 1:34pm |

    Thanks for the fantastic plugin. There seems to be one problem with timezone offset.

    gcal_parse_feed() gives me a list with the correct times (using an offset of 10800), but clicking through to event details shows the incorrect time for a visitor without a google account.

    Embedding a google calendar leads to the same event details page, but seems to retain timezone settings. It’s URL finishes with ctz=America/New_York

    thanks again!

  7. Denis says;
    18 May 2009 - 11:21am |


    I confirm the bug underlined in http://wordpress.org/support/topic/270379?replies=2

    After activating in my sidebar, the page outputs “Warning: SimpleXMLElement::__construct() [simplexmlelement.–construct]: Entity: line 1: parser error : Start tag expected” etc…
    Those PHP warnings I guess I could hide, but then I get a

    “Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in..”

    Wish I could use that plugin, looks promising ! let me know if i can help understand and debug.

    Using WP 2.7.1 on a very recent Linux dedicated server.


  8. Colin says;
    21 May 2009 - 3:36pm |

    Having the same trouble as ‘bjh’. My XML url works fine in the broswer:


    Yet, when I insert this as the Feed url on the Google Calendar Feed Parser Settings page, then enable the ‘Executable PHP widget’ for the sidebar, then insert the code into that widget…. it returns all the same text as ‘bjh’ mentions above.

    Any ideas? Thanks!

  9. Wayne says;
    27 May 2009 - 2:21am |

    I have a few questions.

    Is there a way to force a hard return between the date and the time?

  10. Ryan says;
    01 Jun 2009 - 1:00am |

    Great plugin! Work great. @bjh – Check and see if the url you put in your admin panel was “http://” and not “feed://”. That may solve your issue.
    Thanks again!

  11. I’m working on a site that needed Google Calendar feed parsing and found your awesome little plugin. Sweet. Only problem I had with it – it doesn’t work with the current WP 2.7 widget architecture. So, I could have bugged you and begged you to add that, but… Naw, free plugin, you’re probably a busy guy (Lord knows I am) so why not figure it out myself.

    So I did. I upversioned it to 0.4 just to avoid any weird conflicts. You can grab it from here:


    I made a change to the output function – I thought I’d need to extract the display code as a single string (I was wrong) so I wrote a new function (gcal_get_feed_string() ) to replace all the echoes with a single variable that gets returned. I then rewrote the gcal_parse_feed() function to just echo the return from my new function.

    I also added a chunk of code at the top to make the widgets work.

    Let me know if you run into any problems or anything. I tested it on my install and, so far, so good.

    Rob Z.

  12. OH – and I rewrote the code that grabs maxresults – I’m using this for a Google Apps calendar and, apparently, the feed url for it doesn’t accept the maxresults query string variable. So, you’ll get the firehose when you grab the calendar. This… needs to be reworked, methinks.

  13. I updated the parer again. It turns out I was not using the “full” version of the feed, hence why the maxresults wasn’t working. I set it back the way it was (still with the widget intact) and posted it on my site for future reference:


  14. Kevin says;
    09 Jun 2009 - 11:59am |

    bjh – it appears that if the gcal parser can’t get a response from google then it goes haywire and fails. I have been having this problem too, but google calendar appears to be down for domain users. It would be great to have error handling for this circumstance because I don’t want my users seeing a bunch of garbage if there is no feed available… caching also might help both reduce server load and prevent shorterm google outages from affecting users.

  15. Do you have instructions somewhere on how to style the CSS for the results? I see that you have a screenshot with styled results, but can’t figure out how you did that. I put the code in my sidebar.php file, but am not sure how to style around it.


  16. Kristoffer says;
    10 Jun 2009 - 6:53pm |

    I have the exakt problem as bjh, tried the feed URL in a browser and that works fine…

  17. Scott Clark says;
    15 Jun 2009 - 5:44pm |

    Just added this to a WP 2.8 site… got this:

    Parse error: parse error, unexpected T_OBJECT_OPERATOR gcalparse.php on line 112

    Tried re-install.


  18. Sumair says;
    15 Jun 2009 - 9:36pm |


    I tried setting up and pointing to the url : http://www.google.com/calendar/feeds/xxxx.com/public/basic for the feed url and tried pasting “” into the html code of a page but it doesnt seem to work…

    any idea how i can get this working?


  19. Eric says;
    16 Jun 2009 - 2:03am |

    Man, I’m a complete noob with no programming background. What is a call function? I’ve tried googling this and it’s like reading greek to me.

  20. Can you help me either not show endtimes or show enddates with the endtimes?

  21. Hi,
    What do I have to change in the code in order to retrieve information from the google calendar such as location of the event and the description?


  22. Hey there… Awesome plugin. I am trying to recreate what you did on your screenshot, however I am having some trouble. I put in the XML feed URL in the settings area and also in the RSS feed widget on my sidebar. When I do this it brings up events with the wrong date and it repeats them. Not quite sure what’s happening, but how do I do what you did on your example screenshot? Thanks

  23. rpicrew says;
    17 Jul 2009 - 1:40am |

    I have the same question as Lucas. Is there a way to implement this on one of my pages on my site? I’d like to implement this without editing any templates.

    Any help would be appreciated.

  24. Before, you’d click the link, and the box would pop up. Now it just opens the whole thing, so you have to hit “back” to get back. What went wrong? Does it not support the most recent version of WordPress? It worked fine before I upgraded to the latest version.


  25. Thanks for the neat plugin! I am a novice at all of this, but am wondering if there is any way to better handle “All Day” events from the Google Calendar. They are being displayed as a 2:00am start time for me (in in Raleigh: EDT). What I’d like is a condition that if 2:00am is the start time, then just suppress \f\r\o\m\ and onward (just display a date – no time – for these events).


  26. Still having a problem with All Day events. I dug into this a little more and found that Google Calendar does not send a Time variable for all day events. So what I really want is an “If/Else” scenario where all day events result with only the date displayed, and all others show the date and time. I just don’t have the PHP skills to build the If line for handling events with no time parameter. Help!!

    Also, I would like to display the list if items grouped by day. This page does exactly what I mean.
    He has the current date, then all of the events on that date and so on. How can we do a query like this?

  27. update: based on what arley commented above i also changed “basic” to “full” in the url to avoid further errors.

  28. Love the idea of your plug-in. I have something similiar on the site now, but would love to have it come from a Google calendar. Just way more flexible. But I’m pretty new at this, so I am having a problem. I uploaded the parser to the site and that part works. Then I put in the URL of the calendar (I think). I got it by going under Calendar Details for my calendar and then picking HTML and then cutting and pasting the whole string into the Parser settings. Then I opened the Widget tab, added a text box, and cut and paste the PHP code into the text field. When I try it, I get a textbox, but there are no dates in the box. Is that not a valid way to use the parser? I am using some prepurchased templates (Artisteer), so I don’t have much knowledge of the construction of my site. Thanks in advance. Lene

  29. Justin says;
    26 Oct 2009 - 9:13pm |


    First, you will want to choose “RSS” in your Calendar Details as opposed to “HTML”. Second, I’m not certain that the plugin will work within the Widget interface. If changing to the RSS format as I mentioned doesn’t fix the problem, try copying the php code for my plugin directly into your theme’s template (typically the files will be titled well, so if you want the calendar feed to appear in the sidebar, try looking at your theme’s sidebar.php in the theme editor). Also, you may want to look through some of the comments on this post as well as the other parser-related posts on my blog for mention of a widgetized version of my plugin (I know someone created one I just can’t remember where I talked about it).

    Let me know if you have any other issues.


  30. sarah says;
    03 Nov 2009 - 10:35am |

    one stupid question but where am I to find this
    Feed URL: This is the URL of the feed you wish to incorporate in your blog. It should be of the form:

    I have a google calendar but can’t seem to find the url of the feed…

  31. […] Google Calendar Feed Parser […]

  32. […] been using Google Calendar Feed Parser to generate a sidebar box with upcoming events for quite a few websites. It’s a handy little […]

  33. Ryan Regalado says;
    21 Nov 2009 - 1:51pm |

    Hello everyone. With the issue of “parser error : Start tag expected”

    I did a little debugging and found out that the hard-coded feed parameter of “&max-results” was causing the issue. I commented out this line and got it to work but still need to figure out how to get only the first 3 to 5 items instead of all of them.

    //$feed_url .= ‘&max-results=’ . (( get_option(‘gcal_max_results’) == ” ) ? ‘4’ : get_option(‘gcal_max_results’));

    I need to learn these feed parameters

  34. I’ve tried adding the function directly to the template, but when I do, everything from the call on in the template disappears. Any HTML or php just disappears.

    I tried putting in echo statements before and after the call and it is clearly the call that’s aggravating things.


    Any ideas?

  35. Changed the timezone offset to -18000 to fix it for now.

  36. I have a problem with the time displayed for my calendar. I tweaked the code to adjust the display and everything works great on the home page. But on every other page, the time is displayed off by 5 hours, as GMT. When I click on the link, the time is displayed by Google correctly.

    Here is the Feed URL

  37. Ever since daylight savings time, my calendar is off in the upcoming events by an hour…but it’s right in the Google Calendar page.
    I changed the seconds offset, and it fixed some…but now others are a day early.

  38. I have restored the current version of the code and still have the same problem. The behavior of the code is different on home pages than on other pages. I have tried this on both the Titanium abd bChurch themes from iThemes.
    My offset is 0, not the default 7200.

  39. Justin says;
    31 Mar 2010 - 9:15am |


    When I initially designed this plugin I ran into the issue of timezones, as you are both seeing. The problem is that Google, your web server and PHP are all configured for a particular timezone, which may or may not be the timezone you’re actually in. I attempted to compensate for misinterpreted times by including the customizable offset, which works in many cases.

    Chuck, the problem you’re seeing with some events being off by a day is certainly odd and not one that I’d heard of yet.

    I have a few ideas for ways I could remedy these issues. I will try to do some research in the coming days and will certainly let you know via a comment here and a new blog post if I come up with anything that will help you. (maybe it’s time for a 0.4!)

Add a Comment