Development · Web · WordPress

How To Insert a Back Button in HTML and WordPress

How to Insert Back Button in WordPress

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:

function goBack() { window.history.back() }

In the BODY section, add the actual back button

<button onclick="goBack()">Go Back</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 onclick="goBack()">Go Back</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 and  How to Set Up WordPress in a Different Directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge