Last active
September 22, 2022 07:37
-
-
Save alamgircsebd/408daaaf0a6fb6eb5a8029b3853fa884 to your computer and use it in GitHub Desktop.
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
<?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