This quick tip shows how to insert a back button in HTML and WordPress which allows your user to navigate to the previous page. This is especially useful if you are developing a tool or a page which contains some user-generated information and you want to go back to the page with the user-generated information retained in the respective input fields.
How To Insert a Back Button in HTML
Simply insert the below code in your HTML file
In the HEAD section, declare the following function:
<script>
function goBack() { window.history.back() }
</script>
In the BODY section, add the actual back button
<button >
How To Insert a Back Button in WordPress
Simply insert the following code in your WordPress page or post in the Text mode of the editor.
<script>// <![CDATA[
function goBack() { window.history.back() }
// ]]></script>
<button >
Note: When adding the Go Back button in Word press, ensure you hit the Publish or Update buttons directly from the Text Editor mode as the Visual mode removes the onclick attribute of the button.
Let us know if this tip helped you using the comments section below.
You might also want to read up on How to Redirect 404 pages in WordPress, How to reset WordPress password from cPanel and How to Set Up WordPress in a Different Directory.
If you think that you have a link that adds value to this article please contact us at techie[at]techzog[dot]com for evaluation of inclusion into the article.
Comments left solely for spamming links will be deleted. Thank you for understanding.
View Comments (10)
This does not work in Beaver Builder either.
WordPress sucks. So does Beaver Builder. None of this simple crap should be this hard and take hours to figure out.
Hi there,
still working like a charm, but how can i change the style? with just additional css?
BR, Thomas
Yes, you can change the button style with HTML attributes or then apply a style from your theme or through CSS
This doesn't work with (html widget in) Elementor
This works great, thanks
It does not work on Wordpress. Maybe I did something wrong? I inserted the code directly into the text editor
You can insert the code directly in the Wordpress Editor but in 'Text' mode. Inserting it in 'Visual' mode won't work.
You are a genius! Thanks!
Thank you :)
EXACTLY what I needed man! Thanks.