WP Simple Booking Calendar Shortcode

Below, you’ll find a detailed guide on how to add the WP Simple Booking 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 WP Simple Booking Calendar Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the WP Simple Booking Calendar Plugin and the shortcodes it provides:

Plugin Icon
WP Simple Booking Calendar

"WP Simple Booking Calendar is a user-friendly WordPress plugin that allows you to effortlessly manage and display booking calendars on your website, simplifying your scheduling tasks."

★★★★☆ (216) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [wpsbc]

WP Simple Booking Calendar [wpsbc] Shortcode

The wp-simple-booking-calendar shortcode is designed to display a single calendar on your WordPress site. It allows customization of title, legend, and language. The shortcode attributes provide flexibility in presenting the calendar. If the calendar doesn’t exist, it displays a user-friendly error message.

Shortcode: [wpsbc]

Parameters

Here is a list of all possible wpsbc shortcode parameters and attributes:

  • id – Unique identifier for the calendar to be displayed.
  • title – Controls if the calendar title is displayed. ‘yes’ shows the title, ‘no’ hides it.
  • legend – Determines if the calendar legend is shown. ‘yes’ to display, ‘no’ to hide.
  • legend_position – Sets the position of the legend. Empty value removes the legend.
  • language – Sets the calendar language. ‘auto’ uses the site’s default language.

Examples and Usage

Basic example – Display a simple booking calendar with the ID of 1.

[wpsbc id=1 /]

Advanced examples

Display a booking calendar with the ID of 1, showing the calendar title but without the legend.

[wpsbc id=1 title='yes' legend='no' /]

Display a booking calendar with the ID of 2, showing both the calendar title and the legend. The legend is positioned at the bottom of the calendar and the calendar language is set to Spanish.

[wpsbc id=2 title='yes' legend='yes' legend_position='bottom' language='es' /]

Display a booking calendar with the ID of 3, without the calendar title and the legend. The calendar language is set to auto, which means it will automatically detect the language of your WordPress site.

[wpsbc id=3 title='no' legend='no' language='auto' /]

PHP Function Code

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

Shortcode line:

add_shortcode('wpsbc', array(__CLASS__, 'single_calendar'));

Shortcode PHP function:

function single_calendar($atts)
    {

        // Shortcode default attributes
        $default_atts = array(
            'id' => 1,
            'title' => 'yes',
            'legend' => 'no',
            'legend_position' => '',
            'language' => 'auto',
        );

        // Shortcode attributes
        $atts = shortcode_atts($default_atts, $atts);

        // Calendar outputter default arguments
        $default_args = wpsbc_get_calendar_output_default_args();

        // Translating values from the shortcode attributes to the calendar arguments
        $args = array(
            'show_title' => (!empty($atts['title']) && $atts['title'] == 'yes' ? 1 : 0),
            'show_legend' => (!empty($atts['legend']) && $atts['legend'] == 'yes' ? 1 : 0),
            'legend_position' => $atts['legend_position'],
            'current_month' => current_time('n'),
            'current_year' => current_time('Y'),
            'language' => ($atts['language'] == 'auto' ? wpsbc_get_locale() : $atts['language']),
        );

        // Remove legend_position if it's empty
        if (empty($args['legend_position'])) {
            unset($args['legend_position']);
        }

        // Calendar arguments
        $calendar_args = wp_parse_args($args, $default_args);

        // Calendar id
        $calendar_id = (!empty($atts['id']) ? (int) $atts['id'] : 0);

        // Calendar
        $calendar = wpsbc_get_calendar($calendar_id);

        if (is_null($calendar)) {

            $output = '<p>' . __('Calendar does not exist.', 'wp-simple-booking-calendar') . '</p>';

        } else {

            // Initialize the calendar outputter
            $calendar_outputter = new WPSBC_Calendar_Outputter($calendar, $calendar_args);

            $output = $calendar_outputter->get_display();

        }

        return $output;

    }

Code file location:

wp-simple-booking-calendar/wp-simple-booking-calendar/includes/base/class-shortcodes.php

Conclusion

Now that you’ve learned how to embed the WP Simple Booking 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.

Comments

Leave a Reply

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