Created
April 19, 2019 17:44
-
-
Save vladi160/aac975190e00303f1162b72095029702 to your computer and use it in GitHub Desktop.
Set client routing for WordPress
This file contains 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
// Get current route | |
function vsi_get_current_route(){ | |
$routeWithParams = explode('/', $_SERVER['REQUEST_URI'])[1]; | |
return parse_url($routeWithParams, PHP_URL_PATH); | |
} | |
add_filter( '404_template_hierarchy', 'vsi_client_routing' ); | |
function vsi_client_routing() { | |
$router = new CompanyRouter(); | |
$currentRoute = vsi_get_current_route(); | |
// if there is a defined client side route /contacts | |
// render / only for specific 404 routes, but not for all. Remove the check for all | |
if($currentRoute === 'contacts'){ | |
status_header(200); | |
// Set the title | |
add_filter("pre_get_document_title", function($old_title){ | |
return "Contacts"; | |
}); | |
return locate_template( array('index.php')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment