Event Calendar: How to load to a specific month, rather than current month (Month View)

Any ideas how to set the month view on Event Calendar to set to a specific month i.e June?

2 Likes

Hi there, @user2343 :wave:

Do I get it right that you’d like to skip months without events and show the month, where you have the closest event by default?

If this is the case, this code will help you achieve this:

let eventsInCalendar = 0;
const myInterval = setInterval(() => {
	const calendar = document.getElementsByClassName('fc-daygrid-day');
	let eventInTheCurrentMonth = false;
	for(let i = 0; i < calendar.length; i++) {
		let month = calendar[13].getAttribute('data-date').split('-')[1];
		let currentEventMonth = calendar[i].getAttribute('data-date').split('-')[1];
		eventInTheCurrentMonth = month == currentEventMonth;

		if(calendar[i].innerHTML.includes('fc-event-start') == 1 && eventInTheCurrentMonth) {
			eventsInCalendar++;
		}
	}
	
	if (eventsInCalendar == 0) {
		const buttonNext = document.querySelector('[class*="next-button"]');
		buttonNext.click();
		
	} else {
		clearInterval(myInterval);	
	}
}, 300);

Please add it to the Custom JS field on the Settings tab of your widget’s settings and let me know if it helped :slightly_smiling_face:

2 Likes

Hey @Max!

Echoing the OP’s question – Is it possible to have the calendar load to a specified month (ex. June 2026) rather than the current month?

Thanks!

2 Likes

Hey there and welcome aboard, @user618303 :waving_hand:

Yep, the code from the message above should work great. Please add it to the Custom JS field on the Settings tab of your widget’s settings and let me know if it helped :slightly_smiling_face:

Note: Custom JS operates only upon widget installation, not in preview mode.

1 Like

Hi @Max – thanks for the quick reply!

Unfortunately, when published on the live site, the code advances the calendar but does not stop advancing, despite there being months with events.

2 Likes

Could you please send me a link to the page, where your widget is installed? I’ll be happy to check it for you :slightly_smiling_face:

2 Likes