Skip to content

Instantly share code, notes, and snippets.

@AndryWJ
Last active December 18, 2023 12:37
Show Gist options
  • Select an option

  • Save AndryWJ/fe6f0a4812982b14011b3100f55f8677 to your computer and use it in GitHub Desktop.

Select an option

Save AndryWJ/fe6f0a4812982b14011b3100f55f8677 to your computer and use it in GitHub Desktop.
wp:php custom routing wordpress
add_filter( 'init', function(){
add_rewrite_rule(
'^bx24app/(.*)/?$',
'index.php?bx24app=$matches[1]',
'top'
);
add_filter( 'query_vars', function($vars){
$vars[] = 'bx24app';
return $vars;
});
add_action( 'template_redirect', function(){
if( $bx24app = get_query_var( 'bx24app' ) ){
$path = PLUGIN_DIR . '/modules/bitrix_app/'.$bx24app.'.php';
if(file_exists($path)){
include_once $path;
exit();
}else{
status_header( 404 ); nocache_headers(); include( get_query_template( '404' ) );
die();
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment