php - Wordpress URL Rewrite is not working -


i trying create own permalink , use custom template rewrite rule. here how wanted url http://example.com/author/{author-id}

my custom url

function prefix_author_rewrite_rule() {     add_rewrite_rule( 'author/([^/]*)', 'index.php?id=$matches[1]', 'top' ); }  add_action( 'init', 'prefix_author_rewrite_rule' ); 

my query vars

function prefix_register_query_var( $vars ) {     $vars[] = 'id';      return $vars; } add_filter( 'query_vars', 'prefix_register_query_var' ); 

set template

function prefix_url_rewrite_templates() {      if ( get_query_var( 'id' ) ) {         add_filter( 'template_include', function() {             return get_template_directory() . '/author-details.php';         });     } }  add_action( 'template_redirect', 'prefix_url_rewrite_templates' ); 

so if type url http://example.com/author/32 won't load author-details.php instead giving me blank page. referring link https://code.tutsplus.com/articles/custom-page-template-page-based-on-url-rewrite--wp-30564


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -