Back button redirect

Norman_drey

Senior Member
Joined
May 8, 2022
Messages
1,156
Reaction score
496
Is there any script or plugin I can redirect user to a specific page when they hit back button?
(WordPress)
 
functions.php

function redirect_on_back() {
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == get_permalink()) {
wp_redirect('https://example.com/redirect-page');
exit;
}
}
add_action('template_redirect', 'redirect_on_back');

This code checks if the user has come back from the same page they are currently on (get_permalink()), and if so, redirects them to the specified page.
 
functions.php



This code checks if the user has come back from the same page they are currently on (get_permalink()), and if so, redirects them to the specified page.
I don't understand this code
 
JavaScript:
  var perfEntries = performance.getEntriesByType("navigation");

  if (perfEntries[0].type === "back_forward") {

    location.replace("https://www.google.com");

  }
Replace https://www.google.com with custom URL
 
JavaScript:
  var perfEntries = performance.getEntriesByType("navigation");

  if (perfEntries[0].type === "back_forward") {

    location.replace("https://www.google.com");

  }
Replace https://www.google.com with custom URL
Thank you
Where do I add this.
Function.php
Any post page
Header or where?
 
You asked for a script, @EWRITERS provides you with some code to work with, you dont understand code!

Then either learn code, pay someone to do it for you or accept you cannot add / edit code on your site.
I added it and it didn't work that's why I said so.
Screenshot_20230319-102814.png
 
Back
Top