Skip to content

Instantly share code, notes, and snippets.

@tamarazuk
Last active December 25, 2015 16:09
Show Gist options
  • Save tamarazuk/7004172 to your computer and use it in GitHub Desktop.
Save tamarazuk/7004172 to your computer and use it in GitHub Desktop.
Fixes a 'popstate' issue with The Events Calendar WordPress plugin. Issue described full detail here: https://tri.be/support/forums/topic/category-feed-lost-after-viewing-single-event-going-back-to-category/#post-68858
<?php
function namespace_temp_fix_tribe_cat() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
if ( typeof(tribe_ev) !== 'undefined' ) {
var trive_ev_cat = tribe_ev.fn.get_category();
if (trive_ev_cat && trive_ev_cat != "") {
if ( typeof(tribe_ev.data.params) == 'string' ) {
tribe_ev.data.params += 'tribe_event_category=' + trive_ev_cat;
} else {
tribe_ev.data.params["tribe_event_category"] = trive_ev_cat;
}
}
}
});
</script>
<?php
}
add_action('wp_head', 'namespace_temp_fix_tribe_cat', 8); // high priprity to make sure it is added before TEC js files
function namespace_tribe_events_view_data_attributes($data_attributes) {
$data_attributes['category'] = get_query_var('tribe_events_cat') ? get_query_var('tribe_events_cat') : '';
return $data_attributes;
}
add_filter('tribe_events_view_data_attributes', 'namespace_tribe_events_view_data_attributes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment