Skip to content

Instantly share code, notes, and snippets.

@elimn
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elimn/755ab345963c7469075c to your computer and use it in GitHub Desktop.
Save elimn/755ab345963c7469075c to your computer and use it in GitHub Desktop.
MT | TEC | Set Events Category Default View
<?php
// Overrides every request for viewOption from TribeEvents::getOption()
function tribe_swap_default_category_view ($option, $default, $optionName) {
// For a list of acceptable views/values run print_r(tribe_events_enabled_views());
$default_events_view = 'month'; // The default view for the main page, venue, etc.
$default_category_view = 'list'; // The default view for any calendar category
if ($optionName === 'viewOption') {
// Default category view is saved as a rewrite rule
// Every other view checks viewOption on front-end page load
// Hack: Since rewrites are usually only saved/flushed from the admin area, check that
if( is_admin() ) {
$option = $default_category_view;
} else {
$option = $default_events_view;
}
}
return $option;
}
add_filter('tribe_get_single_option', 'tribe_swap_default_category_view', 1, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment