Skip to content

Instantly share code, notes, and snippets.

@vladi160
Created April 19, 2019 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladi160/aac975190e00303f1162b72095029702 to your computer and use it in GitHub Desktop.
Save vladi160/aac975190e00303f1162b72095029702 to your computer and use it in GitHub Desktop.
Set client routing for WordPress
// 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