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 ) {
$viewsToRemove = [
'listMonth',
'timeGridWeek',
'listWeek',
'dayGridWeek',
];
return array_values( array_diff( $views, $viewsToRemove ) );
}, 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();
}
});