Created
March 9, 2015 14:58
-
-
Save matesnippets/5d82981aff50a64caa77 to your computer and use it in GitHub Desktop.
WordPress, intelligent back link to previous page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Returns a URL to the page where user was before this page | |
| * @param string $domain The sites domain name | |
| * @param string $exeption_path The path to go to if not referer is not your site | |
| * @return string URL string | |
| */ | |
| function pps_back_href($domain, $exeption_path) | |
| { | |
| // Get the referer, aka where user comes | |
| $referer = htmlspecialchars($_SERVER['HTTP_REFERER']); | |
| // Regex pattern | |
| $match_pattern = "/\$domain/"; | |
| // Has your site name in it | |
| if (preg_match($match_pattern, $referer)) { | |
| return $referer; | |
| } else { | |
| // Where to go if the referer is not from your domain | |
| return $domain.'/'.$exeption_path; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment