Norman_drey
Senior Member
- May 8, 2022
- 1,156
- 496
Is there any script or plugin I can redirect user to a specific page when they hit back button?
(WordPress)
(WordPress)
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');
I don't understand this codefunctions.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.
You asked for a script, @EWRITERS provides you with some code to work with, you dont understand code!I don't understand this code
var perfEntries = performance.getEntriesByType("navigation");
if (perfEntries[0].type === "back_forward") {
location.replace("https://www.google.com");
}
Thank youReplace https://www.google.com with custom URLJavaScript:var perfEntries = performance.getEntriesByType("navigation"); if (perfEntries[0].type === "back_forward") { location.replace("https://www.google.com"); }
I added it and it didn't work that's why I said so.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.

Header.php - in between <head> and </head>Thank you
Where do I add this.
Function.php
Any post page
Header or where?
Not working, I think the script is incompleteHeader.php - in between <head> and </head>
There are WP Plugins that can do this too. https://wordpress.org/plugins/wp-headers-and-footers/
If you don't want to use functions.php, you can simply use this plugin:
https://wpfactory.com/item/back-button-widget-wordpress-plugin/