Skip to content

Instantly share code, notes, and snippets.

@alamgircsebd
Last active September 22, 2022 07:37
Show Gist options
  • Save alamgircsebd/408daaaf0a6fb6eb5a8029b3853fa884 to your computer and use it in GitHub Desktop.
Save alamgircsebd/408daaaf0a6fb6eb5a8029b3853fa884 to your computer and use it in GitHub Desktop.
<?php
function custom_rewrite_basic() {
add_rewrite_endpoint( 'custom_slug', EP_PAGES );
add_rewrite_rule( 'custom_slug/([^/]+)/?$', 'index.php?custom_slug=$matches[1]', 'top' );
}
add_action( 'init', 'custom_rewrite_basic' );
function custom_register_query_var( $vars ) {
$vars[] = 'custom_slug';
return $vars;
}
add_filter( 'query_vars', 'custom_register_query_var' );
add_action( 'template_include', function( $template ) {
if ( get_query_var( 'custom_slug' ) == false || get_query_var( 'custom_slug' ) == '' ) {
return $template;
}
return get_template_directory() . '/custom_slug-template.php';
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment