-1

I would like to add "back buttons" to every page in my Wordpress site..and I'd like it to appear at the top of each page. How do I code that and where is it placed on the page code? thank you, Lori

closed as too broad by Mark Kaplun, Howdy_McGee, TheDeadMedic, kaiser Apr 8 '16 at 13:14

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

You can use following code. I trust you can style the link to look like button :)

if( wp_get_referer() )
  echo '<a href="'<?php wp_get_referer() ?> '" >BACK</a>';
1

Back Button

I combine @ItsMePN answer with how WordPress handling back page on error page - wp_die. It's JavaScript. onclick='javascript:history.back()'

https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/functions.php#L2537

Add into theme functions.php

add_action( 'back_button', 'wpse221640_back_button' );
function wpse221640_back_button()
{
    if ( wp_get_referer() )
    {
        $back_text = __( '&laquo; Back' );
        $button    = "\n<button id='my-back-button' class='btn button my-back-button' onclick='javascript:history.back()'>$back_text</button>";
        echo ( $button );
    }
}

Add into theme header.php after <body>

<?php do_action('back_button'); ?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.