Below, you’ll find a detailed guide on how to add the Events Manager Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Events Manager Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Events Manager Plugin and the shortcodes it provides:
"Events Manager is a versatile WordPress plugin designed to simplify event management. It allows users to register for events, view event calendars, and manage bookings seamlessly."
- [events_calendar]
- [events_gcal]
- [locations_map]
- [events_map]
- [locations_list]
Events Manager Shortcode
The Events Manager shortcode ‘gallery’ is designed to override the default gallery for a specific event. This PHP function checks if the post type is an event and if no specific ID is provided. If the event is a recurrence, it fetches the post ID of the recurrence template and uses it as the gallery ID. This allows the display of a unique gallery for each recurrent event.
Shortcode:
Parameters
Here is a list of all possible gallery shortcode parameters and attributes:
id
– Unique identifier of the eventids
– Array of event identifiers
Examples and Usage
Basic example – A simple usage of the ‘gallery’ shortcode to override the default gallery of an event. This will check if the current post is an event and if it is, it will replace the gallery with the one specified in the shortcode.
Advanced examples
Using the ‘gallery’ shortcode to override the default gallery of a recurring event. If the event is recurring, the gallery will be replaced with the gallery of the recurrence template post. This is useful when you want to display a different set of images for each recurrence of an event.
PHP Function Code
In case you have difficulties debugging what causing issues with shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('gallery', 'em_event_gallery_override');
Shortcode PHP function:
function em_event_gallery_override( $attr = array() ){
global $post;
if( !empty($post->post_type) && $post->post_type == EM_POST_TYPE_EVENT && empty($attr['id']) && empty($attr['ids']) ){
//no id specified, so check if it's recurring and override id with recurrence template post id
$EM_Event = em_get_event($post->ID, 'post_id');
if( $EM_Event->is_recurrence() ){
$attr['id'] = $EM_Event->get_event_recurrence()->post_id;
}
}
return gallery_shortcode($attr);
}
Code file location:
events-manager/events-manager/classes/em-event.php
Events Manager [events_calendar] Shortcode
The Events Manager shortcode, ‘events_calendar’, displays a calendar populated with events. It retrieves event data and outputs it in a calendar format. The PHP function ’em_get_calendar_shortcode’ is linked to this shortcode. It utilizes the EM_Calendar class to output the event data, providing users with a visual representation of events.
Shortcode: [events_calendar]
Examples and Usage
Basic example – A simple events calendar can be displayed using the shortcode with no parameters. The calendar will default to the current month and display all events.
[events_calendar /]
Advanced examples
Specify the month and year of the calendar. This will display the events calendar for October 2022.
[events_calendar month="10" year="2022" /]
Display the events calendar in a specific category. This will show only the events in the category with id 5.
[events_calendar category="5" /]
Combine multiple parameters. This will display the events calendar for October 2022 and only show events in the category with id 5.
[events_calendar month="10" year="2022" category="5" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [events_calendar]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('events_calendar', 'em_get_calendar_shortcode');
Shortcode PHP function:
function em_get_calendar_shortcode($atts) {
return EM_Calendar::output( (array) $atts );
}
Code file location:
events-manager/events-manager/em-shortcode.php
Events Manager [events_gcal] Shortcode
The Events Manager shortcode ‘events_gcal’ generates a Google Calendar button. This button, when clicked, opens the site’s events in Google Calendar. The button’s image can be customized via shortcode attributes.
Shortcode: [events_gcal]
Parameters
Here is a list of all possible events_gcal shortcode parameters and attributes:
img
– URL of the image used as the Google Calendar buttonbutton
– Number to select the Google Calendar button design
Examples and Usage
Basic example – The shortcode displays a Google Calendar button. The button, when clicked, redirects to the Google Calendar page with the events of the website.
[events_gcal /]
Advanced examples
Changing the Google Calendar button image. The shortcode accepts an ‘img’ parameter which is the URL of the image that will be used as the button. Make sure the URL starts with ‘https://’ if your site is SSL secured.
[events_gcal img="https://yourwebsite.com/yourimage.jpg" /]
Using a different Google Calendar button design. Google Calendar offers different button designs numbered from 1 to 6. The ‘button’ parameter accepts these numbers. If the ‘img’ parameter is not specified, the ‘button’ parameter will change the design of the default Google Calendar button.
[events_gcal button=3 /]
Changing both the Google Calendar button image and design. If both ‘img’ and ‘button’ parameters are specified, the ‘button’ parameter will change the design of the specified image.
[events_gcal img="https://yourwebsite.com/yourimage.jpg" button=2 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [events_gcal]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('events_gcal', 'em_get_gcal_shortcode');
Shortcode PHP function:
function em_get_gcal_shortcode($atts){
$img_url = is_ssl() ? 'https://www.google.com/calendar/images/ext/gc_button6.gif':'http://www.google.com/calendar/images/ext/gc_button6.gif';
$atts = shortcode_atts(array('img'=>$img_url, 'button'=>6), $atts);
if( $img_url == $atts['img'] && $atts['button'] != 6 ){
$img_url = str_replace('gc_button6.gif', 'gc_button'.$atts['button'].'.gif', $img_url);
}
$url = '<a href="http://www.google.com/calendar/render?cid='.urlencode(trailingslashit(get_home_url()).'events.ics').'" target="_blank"><img src="'.esc_url($img_url).'" alt="0" border="0"></a>';
return $url;
}
Code file location:
events-manager/events-manager/em-shortcode.php
Events Manager [locations_map] Shortcode
The Events Manager shortcode ‘locations_map’ generates a global map of event locations. It accepts width and height parameters, with default values of 400px and 300px respectively. The shortcode also supports a unique id and custom map style.
Shortcode: [locations_map]
Parameters
Here is a list of all possible locations_map shortcode parameters and attributes:
width
– Defines the width of the map, accepts px or %height
– Determines the height of the map, takes px or %id
– Generates a random unique identifier for the mapmap_style
– Allows for custom styling of the map
Examples and Usage
Basic example – A simple usage of the ‘locations_map’ shortcode without any additional parameters. This will display a map with default width and height settings as per your Events Manager plugin settings.
[locations_map /]
Advanced examples
Using the ‘locations_map’ shortcode with specific width and height parameters. This will override the default settings and display a map with the specified width and height.
[locations_map width="500px" height="500px" /]
Using the ‘locations_map’ shortcode with a unique ID and a specific map style. The unique ID can be useful for custom CSS styling, and the map style parameter allows you to apply a custom map style.
[locations_map id="123" map_style="your_custom_style" /]
Please replace ‘your_custom_style’ with your actual base64 encoded map style.
PHP Function Code
In case you have difficulties debugging what causing issues with [locations_map]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('locations_map', 'em_get_locations_map_shortcode');
Shortcode PHP function:
function em_get_locations_map_shortcode($args){
$args = (array) $args;
$args['em_ajax'] = true;
$args['query'] = 'GlobalMapData';
//get dimensions with px or % added in
$width = (isset($args['width'])) ? $args['width']:get_option('dbem_map_default_width','400px');
$width = preg_match('/(px)|%/', $width) ? $width:$width.'px';
if( $width == 0 || $width == '0px' || $width == '0%' ) $width = 0;
$height = (isset($args['height'])) ? $args['height']:get_option('dbem_map_default_height','300px');
$height = preg_match('/(px)|%/', $height) ? $height:$height.'px';
if( $height == 0 || $height == '0px' || $height == '0%' ) $height = 0;
$args['width'] = $width;
$args['height'] = $height;
//assign random number for element id reference
if( !empty($args['id']) ) $args['id'] = rand(100, getrandmax());
//add JSON style to map
$style = '';
if( !empty($args['map_style']) ){
$style= wp_kses_data(base64_decode($args['map_style']));
$style_json= json_decode($style);
if( is_array($style_json) || is_object($style_json) ){
$style = preg_replace('/[\r\n\t\s]/', '', $style);
}else{
$style = '';
}
unset($args['map_style']);
}
ob_start();
em_locate_template('templates/map-global.php',true, array('args'=>$args, 'map_json_style' => $style));
return ob_get_clean();
}
Code file location:
events-manager/events-manager/em-shortcode.php
Events Manager [events_map] Shortcode
The Events Manager shortcode, ‘events_map’, generates a customizable global map showcasing event locations. It accepts parameters for width, height, and map style. If no dimensions are specified, default settings are used. It also assigns a random ID to each map for unique identification. The map style is decoded from base64 and applied if valid. The content is then buffered and returned, ready to be displayed on your WordPress site.
Shortcode: [events_map]
Parameters
Here is a list of all possible events_map shortcode parameters and attributes:
em_ajax
– enables Ajax functionality for the mapquery
– specifies the global events map datawidth
– sets the width of the map, default is 400pxheight
– sets the height of the map, default is 300pxid
– assigns a random unique identifier to the mapmap_style
– allows for custom map styling
Examples and Usage
Basic example – Display a global events map with default dimensions
[events_map /]
When using the basic shortcode, the events map will be displayed with default dimensions of 400px width and 300px height. These default dimensions can be changed in the plugin settings.
Advanced examples
Display a global events map with custom dimensions
[events_map width="500px" height="350px" /]
In this example, the shortcode is used to display a global events map with custom dimensions. The width is set to 500px and the height is set to 350px.
Display a global events map with a specific style
[events_map map_style="base64_encoded_style" /]
This advanced example shows how to use the shortcode to display a global events map with a specific style. The style should be a base64 encoded string representing the JSON style for the map.
Display a global events map with a unique id
[events_map id="unique_id" /]
In this example, the shortcode is used to display a global events map with a unique id. This can be useful when you want to reference the map in your custom scripts or styles.
PHP Function Code
In case you have difficulties debugging what causing issues with [events_map]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('events_map', 'em_get_events_map_shortcode');
Shortcode PHP function:
function em_get_events_map_shortcode($args){
$args = (array) $args;
$args['em_ajax'] = true;
$args['query'] = 'GlobalEventsMapData';
//get dimensions with px or % added in
$width = (isset($args['width'])) ? $args['width']:get_option('dbem_map_default_width','400px');
$width = preg_match('/(px)|%/', $width) ? $width:$width.'px';
if( $width == 0 || $width == '0px' || $width == '0%' ) $width = 0;
$height = (isset($args['height'])) ? $args['height']:get_option('dbem_map_default_height','300px');
$height = preg_match('/(px)|%/', $height) ? $height:$height.'px';
if( $height == 0 || $height == '0px' || $height == '0%' ) $height = 0;
$args['width'] = $width;
$args['height'] = $height;
//assign random number for element id reference
if( !empty($args['id']) ) $args['id'] = rand(100, getrandmax());
//add JSON style to map
$style = '';
if( !empty($args['map_style']) ){
$style= wp_kses_data(base64_decode($args['map_style']));
$style_json= json_decode($style);
if( is_array($style_json) || is_object($style_json) ){
$style = preg_replace('/[\r\n\t\s]/', '', $style);
}else{
$style = '';
}
unset($args['map_style']);
}
ob_start();
em_locate_template('templates/map-global.php',true, array('args'=>$args, 'map_json_style' => $style));
return ob_get_clean();
}
Code file location:
events-manager/events-manager/em-shortcode.php
Events Manager [locations_list] Shortcode
The Events Manager plugin shortcode, ‘locations_list’, is designed to display a list of event locations. It utilizes AJAX for dynamic content loading and supports pagination. This shortcode allows customization through various parameters like ‘format’, ‘limit’, and ‘ajax’. The ‘format’ parameter controls how the locations are displayed. The ‘limit’ parameter sets the number of locations to be shown, and ‘ajax’ enables or disables AJAX. The shortcode also includes a unique ID for each instance, ensuring multiple uses on a single page won’t conflict. It also features fallbacks to default templates if no custom format is provided.
Shortcode: [locations_list]
Parameters
Here is a list of all possible locations_list shortcode parameters and attributes:
args
– array of arguments for the shortcode functionajax
– determines if AJAX should be used or notformat
– format of the output contentlimit
– sets the maximum number of locationsid
– random unique identifier for the locations listformat_header
– format of the header of the listformat_footer
– format of the footer of the listpagination
– determines if pagination is enabledpage
– the page number to display in the list
Examples and Usage
Basic example – Display a simple list of locations with default settings
[locations_list /]
Advanced examples
Display a list of locations with a limit of 5 locations per page and enable AJAX
[locations_list limit=5 ajax=1 /]
Display a list of locations with pagination enabled and set to the second page
[locations_list pagination=1 page=2 /]
Display a list of locations with a custom format
[locations_list format="#_LOCATIONNAME
#_LOCATIONADDRESS
#_LOCATIONTOWN, #_LOCATIONSTATE /]
Use the shortcode to display a list of locations with a custom ID. The list will load with the specified ID.
[locations_list id=3 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [locations_list]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('locations_list', 'em_get_locations_list_shortcode');
Shortcode PHP function:
function em_get_locations_list_shortcode( $args, $format='' ) {
$args = (array) $args;
$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
$args['format'] = ($format != '' || empty($args['format'])) ? $format : $args['format'];
$args['format'] = html_entity_decode($args['format']); //shorcode doesn't accept html
$args['limit'] = isset($args['limit']) ? $args['limit'] : get_option('dbem_locations_default_limit');
if( !empty($args['id']) ) $args['id'] = rand(100, getrandmax());
if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
ob_start();
if( !empty($args['ajax']) ){ echo '<div class="em-search-ajax">'; } //open AJAX wrapper
em_locate_template('templates/locations-list.php', true, array('args'=>$args));
if( !empty($args['ajax']) ) echo "</div>"; //close AJAX wrapper
$return = ob_get_clean();
}else{
$args['ajax'] = false;
$args['page'] = ( !empty($args['pagination']) && !empty($args['page']) && is_numeric($args['page']) )? $args['page'] : 1;
$args['page'] = ( !empty($args['pagination']) && !empty($_GET['pno']) && is_numeric($_GET['pno']) )? $_GET['pno'] : $args['page'];
$return = EM_Locations::output( $args );
}
return $return;
}
Code file location:
events-manager/events-manager/em-shortcode.php
Conclusion
Now that you’ve learned how to embed the Events Manager Plugin shortcodes, 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