Events Calendar for Google Shortcode

Below, you’ll find a detailed guide on how to add the Events Calendar for Google Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Events Calendar for Google Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Events Calendar for Google Plugin and the shortcodes it provides:

Plugin Icon
Events Calendar for Google

"Events Calendar for Google is a dynamic WordPress plugin that integrates your website with Google Calendar. It seamlessly displays your events, making scheduling and event management effortless."

★★★★✩ (16) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [ECFG_calender_events]

Events Calendar for Google [ECFG_calender_events] Shortcode

The Events-Calendar-for-Google plugin shortcode, ‘ECFG_calender_events’, is a tool that displays calendar events on your WordPress site. It fetches the events, checks if there are any, and if none, it displays an error message. If events are present, it determines the number to show per page and sets up pagination. It then loops through the events, sanitizing and formatting the data before outputting it. The layout can be customized, and a ‘load more’ option is available.

Shortcode: [ECFG_calender_events]

Examples and Usage

Basic example – Display the calendar events using the ‘ECFG_calender_events’ shortcode. This will load all the events available in your Google Calendar on your WordPress site.

[ECFG_calender_events /]

Advanced examples

Display the calendar events with a specific layout. This shortcode example uses the ‘layout’ parameter to specify the layout type. If you have a layout named ‘google_calender’, you can use it as shown below:

[ECFG_calender_events layout="google_calender" /]

Display a limited number of events. This shortcode example uses the ‘events_to_show’ parameter to limit the number of events displayed. If you want to display only 5 events, you can use it as shown below:

[ECFG_calender_events events_to_show="5" /]

Combine multiple parameters. This shortcode example combines the ‘layout’ and ‘events_to_show’ parameters. It displays 5 events with the ‘google_calender’ layout:

[ECFG_calender_events layout="google_calender" events_to_show="5" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ECFG_calender_events] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ECFG_calender_events', array( $plugin_public, 'ECFG_load_calender_events' ) );

Shortcode PHP function:

function ECFG_load_calender_events($attr)
			$output = '';
			$template_function  = new ECFG_template_functions();
			$layout =  $this->layout;
			$events = $template_function->ECFG_get_calender_events();
			$total_events = count($events);
			if($total_events == 0)
				$output.='<div class="gc_errors"><p>No events Found. Please add Some events to your calendar.</p></div>';
			}/*if total events are 0 or empty show error message*/
				$events_to_show = $template_function->ECFG_option_group_field('gc-advanced-settings','gc_pagination','gc_event_per_page');
				$show_pagination = 'block';
				if($events_to_show == '' || $events_to_show == 0 ||  $events_to_show > $total_events)
					$show_pagination = 'none';
					$events_to_show = $total_events;
				$max_pages  = ceil($total_events/$events_to_show);
				$paginate  = $template_function->ECFG_pagainate_link_function($total_events,$events_to_show);
						$output.='<div id="the_gc_events_posts" class="gc_wrapper_event_'.$layout.'">';
						if($layout != '' && $layout == 'google_calender')
							 $output.='<div id="loading">loading...</div>';
							 $output.='<div id="gc_google_calender"></div>';
							$output.='<div id="ecfg_events_wrap" class="the_gc_event_'.$layout.'">';
							for($i = 0; $i < $events_to_show; $i++)
								$start_date = $events[$i]['start_date'];
								$end_date = $events[$i]['end_date'];
								$event_timezone = $events[$i]['timezone'];
								$event_title = sanitize_text_field($events[$i]['name']);
								$event_content = wp_kses_post($events[$i]['description']);
								$event_location = wp_kses_post($events[$i]['location']);
								$event_link = esc_url_raw($events[$i]['link']);
								$alldayevent = $events[$i]['all_day'];
								include plugin_dir_path( dirname( __FILE__ ) ). 'includes/templates/'.$layout.'.php'; 
								$file_included = ob_get_contents();
								$output.= $file_included;  
							}/*end for loop*/	
							$output.='<div class="gc_load_more_events" style="display:'.$show_pagination.'">'.$paginate.'</div>';				
							}/*end for layout condition*/
			}/*Else condition closes*/		

		    return $output; 		

Code file location:



Now that you’ve learned how to embed the Events Calendar for Google Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.


Leave a Reply

Your email address will not be published. Required fields are marked *