Help wiht adding fullcalendar.io to a WordPress page

I've been trying to add this calendar to my wordpress page. And I've followed the documentation, but it's still not showing up. This is what I've done.

I first added this to my child theme functions file:

function fullcalendar_jquery_enqueue() {
    wp_register_script('fullcalendar', "https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js", false, null, true);
    wp_enqueue_script('fullcalendar');
}
add_action("wp_enqueue_scripts", "fullcalendar_jquery_enqueue", 11);

function load_styles() {
    wp_register_style('fullcalendarcss', 'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css');
    wp_register_style('fullcalendarprintcss', 'https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.print.css');
    wp_enqueue_style( 'fullcalendarcss');
    wp_enqueue_style( 'fullcalendarprintcss');
}
add_action('wp_print_styles', 'load_styles');

Then I added this JS to my custom.js file:

jQuery(document).ready(function ($) {
    var calendar = jQuery('#calendar').fullCalendar({
        editable: true,
    });
});

And then I added div id='calendar'/div to one of my pages, but the calendar is not showing up. In the console, it's showing "Uncaught TypeError".

Can someone please take a look and let me know what I might be doing wrong? Thank you!

Topic calendar functions Wordpress javascript

Category Web


Figured it out!

First I passed what Iceable suggested and also added moment script above, like so

wp_register_script('moment', "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js");
    wp_register_script( 'fullcalendar', "https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js", array( 'jquery' ), null, true);

and then I edited JS like so

jQuery(function ($) {

  $('#calendar').fullCalendar({
  })

});

And it showed up!

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.