• Hi

    I have tried these 2 options: Number 2 do not work, and for some strange reason, option 1, works one time, and that is after publishing, after that one click, it do not work anymore… Even after that first click, i can see in my page editor that this code: <a href="javascript:javascript:history.go(-1)">Click here to go back to previous page</a> becomes this code <a>Click here to go back to previous page</a>

    The other option were this code, but it did not work
    <a href="<?php print $_SERVER['HTTP_REFERER'];?>">Go back</a>

Viewing 6 replies - 1 through 6 (of 6 total)
  • If you are using HTML editor in wp-admin stick with the TEXT tab and not bounce between the visual and text tabs. WP will strip tags.

    Place the below code in your theme file:

    <script>
    	function goBack() {
    	window.history.back()
    	}
        </script>

    You can also try it in the visual editor

    Thread Starter hrohibil

    (@hrohibil)

    Ok, when you say my theme file are refereing to the function.php file?

    If you want it to display on every page, try putting it in footer.php.

    No need for it to go in functions.php

    Full code I’ve used below (in footer.php):

    ‘<input type=”button” value=”Previous Page” onclick=”goBack()”>

    <script>
    function goBack() {
    window.history.back()
    }
    </script>’

    https://www.w3schools.com/jsref/met_his_back.asp

    Thread Starter hrohibil

    (@hrohibil)

    Ok. No i dont need it on every page. Just 2 pages.

    So this code
    `<script>
    function goBack() {
    window.history.back()
    }
    </script>’
    Would only go on those 2 pages i need a back button on right??
    Also where in the html do it go, between header or body??

    Add the below to the visual editor for the pages you want the button to show:

    <input type="button" value="Previous Page" onclick="goBack()">
    
    <script>
    function goBack() {
    window.history.back()
    }
    </script>

    The can add a class or ID to style the button.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘A working back to previous page’ is closed to new replies.