Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active August 23, 2018 05:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/60b5acf003fa68ad7803313d662c08e7 to your computer and use it in GitHub Desktop.
Save cliffordp/60b5acf003fa68ad7803313d662c08e7 to your computer and use it in GitHub Desktop.
The Events Calendar: Turn the "All Events" link into a true "Back" button.
<?php
/**
* The Events Calendar: Turn the "All Events" link into a true "Back" button.
*
* Generally not advisable but provided at customer's request:
* https://theeventscalendar.com/support/forums/topic/upcoming-events-8/
*
* @link https://gist.github.com/cliffordp/60b5acf003fa68ad7803313d662c08e7
* @link https://css-tricks.com/snippets/javascript/go-back-button/
* @link https://api.jquery.com/replacewith/
*/
add_action( 'wp_footer', 'cliff_all_events_link_replaced_with_back_button' );
function cliff_all_events_link_replaced_with_back_button() {
wp_enqueue_script( 'jquery' );
?>
<script type="text/javascript">
jQuery( document ).ready( function () {
var all_events = jQuery( 'p.tribe-events-back a' );
// The following line is commented out because an "All Events" link that goes back to say the Blog Posts page would confuse the user.
// var button_text = all_events.text().trim();
var button_text = '&laquo; Go Back';
var new_element = '<input type="button" value="';
new_element += button_text;
new_element += '" onclick="history.back(-1)" />';
all_events.replaceWith( new_element );
} );
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment