This code is useful if you need to use a “Go Back” (to last page) button/link in a page template of your theme.

To add the code, copy the page template from your theme and paste it in your child-theme. Then, edit the copied file.

Where you want to add the link, past the following code:

$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "<a target="_blank" href='$url'>back</a>";

Note: replace “back” with the text that suits you.