Below, you’ll find a detailed guide on how to add the Pretty Google Calendar 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 Pretty Google Calendar Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Pretty Google Calendar Plugin and the shortcodes it provides:
"Pretty Google Calendar is a user-friendly WordPress plugin that seamlessly integrates your Google Calendar with your website. It allows for easy event tracking and provides a visually appealing layout."
- [pretty_google_calendar]
Pretty Google Calendar [pretty_google_calendar] Shortcode
The Pretty Google Calendar shortcode is a tool that allows you to customize and embed a Google Calendar on your WordPress site. It offers customization options like locale, list type, view settings, and more. Additionally, it provides mobile view enforcement, tooltip usage, and link disabling. The calendar is loaded with an AJAX call for optimal performance.
Shortcode: [pretty_google_calendar]
Parameters
Here is a list of all possible pretty_google_calendar shortcode parameters and attributes:
gcal
– Google Calendar’s unique identifierlocale
– Sets the language for the calendarlist_type
– Determines the type of list displayedcustom_list_button
– Customizes the list button textcustom_days
– Sets the number of days shownviews
– Determines the calendar’s view optionsinitial_view
– Sets the initial view when the calendar loadsenforce_listview_on_mobile
– Enforces list view on mobile devicesshow_today_button
– Controls the visibility of the ‘Today’ buttonshow_title
– Controls the visibility of the calendar’s titleid_hash
– Unique identifier for the calendaruse_tooltip
– Determines whether tooltips are usedno_link
– Controls whether the events are clickable or not
Examples and Usage
Basic Example – Display a Google Calendar in English with the default view of ‘dayGridMonth’ and the list type as ‘listCustom’.
[pretty_google_calendar gcal="your_calendar_id" locale="en" list_type="listCustom" initial_view="dayGridMonth"]
Advanced Examples
Display a Google Calendar with a custom list button and custom days. In this example, the calendar will be in English, the list type will be ‘listCustom’, and the initial view will be ‘dayGridMonth’. The custom list button will display ‘My Custom List’ and the calendar will show events for the next 30 days.
[pretty_google_calendar gcal="your_calendar_id" locale="en" list_type="listCustom" initial_view="dayGridMonth" custom_list_button="My Custom List" custom_days="30"]
Display a Google Calendar with additional views and enforce list view on mobile. In this example, the calendar will be in English, the list type will be ‘listCustom’, and the initial view will be ‘dayGridMonth’. Additional views for ‘listDay’, ‘listWeek’, and ‘listYear’ will be available. The calendar will enforce the list view on mobile devices.
[pretty_google_calendar gcal="your_calendar_id" locale="en" list_type="listCustom" initial_view="dayGridMonth" views="dayGridMonth, listDay, listWeek, listYear" enforce_listview_on_mobile="true"]
Display a Google Calendar with tooltips and without links. In this example, the calendar will be in English, the list type will be ‘listCustom’, and the initial view will be ‘dayGridMonth’. Tooltips will be displayed for events, and the events will not contain links.
[pretty_google_calendar gcal="your_calendar_id" locale="en" list_type="listCustom" initial_view="dayGridMonth" use_tooltip="true" no_link="true"]
PHP Function Code
In case you have difficulties debugging what causing issues with [pretty_google_calendar]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('pretty_google_calendar', 'pgcal_shortcode');
Shortcode PHP function:
function pgcal_shortcode($atts) {
$default = array();
$globalSettings = get_option('pgcal_settings', $default);
$args = shortcode_atts(
array(
'gcal' => "",
// 'locale' => $locale,
'locale' => "en",
'list_type' => "listCustom", // listDay, listWeek, listMonth, and listYear also day, week, month, and year
'custom_list_button' => "list",
'custom_days' => "28",
'views' => "dayGridMonth, listCustom",
'initial_view' => "dayGridMonth",
'enforce_listview_on_mobile' => "true",
'show_today_button' => "true",
'show_title' => "true",
'id_hash' => bin2hex(random_bytes(5)),
'use_tooltip' => isset($globalSettings['use_tooltip']) ? "true" : "false",
'no_link' => isset($globalSettings['no_link']) ? "true" : "false",
),
$atts
);
// Add the attributes from the shortcode OVERRIDING the stored settings
$pgcalSettings = $args;
wp_enqueue_script('fullcalendar');
wp_enqueue_script('fc_locales');
if ($pgcalSettings['use_tooltip'] === "true") {
wp_enqueue_script('popper');
wp_enqueue_script('tippy');
wp_enqueue_script('pgcal_tippy');
wp_enqueue_style('pgcal_tippy');
wp_enqueue_style('tippy_light');
}
// Load Local Scripts
wp_enqueue_script('pgcal_helpers');
wp_enqueue_script('pgcal_loader');
// Load Styles
wp_enqueue_style('fullcalendar');
wp_enqueue_style('pgcal_css');
$script = "
document.addEventListener('DOMContentLoaded', function() {
function pgcal_inlineScript(settings) {
var ajaxurl = '" . admin_url('admin-ajax.php') . "';
pgcal_render_calendar(settings, ajaxurl);
}
pgcal_inlineScript(" . json_encode($pgcalSettings) . ");
});
";
wp_add_inline_script('pgcal_loader', $script);
$shortcode_output = "
<div id='pgcalendar-" . $pgcalSettings["id_hash"] . "' class='pgcal-container'>" . esc_html__("loading...", "pretty-google-calendar") . "</div>
<div class='pgcal-branding'>" . esc_html__("Powered by", "pretty-google-calendar") . " <a href='https://wordpress.org/plugins/pretty-google-calendar/'>Pretty Google Calendar</a></div>
";
return $shortcode_output;
}
Code file location:
pretty-google-calendar/pretty-google-calendar/init/init.php
Conclusion
Now that you’ve learned how to embed the Pretty Google Calendar 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