This guide was inspired by building a 404 Page for an upcoming MyListing Starter Site.
It’s very common to see a ‘Back to Home’ button on 404 Pages, and I’ve used them myself, but I wanted a simple solution that allows the button to take the user back to the previous page they were on before they hit the 404 Page.
- Add a button to the page.
- Customize the button as desired without touching any ‘Link’ settings.
- Button > Advanced Tab > CSS ID > Add ‘back-button’ for the ID. (Note: Watch the video tutorial if you get stuck.)
- Add an Elementor HTML widget to any location on the page (it will not be visible to users).
- Add the code snippet below to the HTML widget.
- Save changes.
JavaScript
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#back-button').on('click', function() {
window.history.go(-1);
return false;
});
});
</script> 