Removing views from the dropdown list

This PHP snippet provides an example of how to remove specific views from Pie Calendar on the front-end. This will not impact the views available in the Block interface on the back-end.

add_filter( 'piecal_allowed_views', function( $views ) {
	error_log( print_r( $views, true ) );
	
	$viewToRemove = 'listMonthWithFeaturedImage';
	
	$indexOfView = array_search( $viewToRemove, $views );
	
	if( $indexOfView != null ) {
		unset( $views[$indexOfView] );
	}
	
	return $views;
}, 999 );

Alternative: JavaScript Only

This approach uses only JavaScript and the snippet must be placed on the front-end where the calendar is being loaded. It is recommended to use the PHP approach, but in some cases, using JavaScript may be preferable or required.

var ready = (callback) => {
	if (document.readyState != "loading") callback();
	else document.addEventListener("DOMContentLoaded", callback);
}

ready(() => { 
	const removableViews = ['dayGridMonth', 'listMonth', 'timeGridWeek'];
	let options = document.querySelectorAll('.piecal-controls__view-chooser option');
	for( let option of options ) {
		if( removableViews.includes( option.getAttribute( 'value' ) ) ) option.remove();
	}
});
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.