php - WordPress add_rewrite_rule for user login in URL -
i'd able use user's login name in url, , grab use within page template. this:
mywebsite.com/admin/users/user/{user_login}
i've tried following, query_var doesn't added query , match stripped end of url, this:
mywebsite.com/admin/users/user/login-name/ --> mywebsite.com/admin/users/user/
i know rewrite happening, because takes me "user" page, can't seem user login come it.
/* add query var */ function add_user_query_vars($query_vars){ $query_vars[] = 'user_login'; return $query_vars; } add_filter('query_vars', 'add_user_query_vars'); /* add rewrite rule */ function add_user_rewrite_rules($rules){ $user_rules = array('admin/users/user/([a-za-z0-9\._-]+)/?$' => 'index.php?pagename=user&user_login=$matches[1]'); $rules = $user_rules + $rules; return $rules; } add_filter('rewrite_rules_array', 'add_user_rewrite_rules');
thanks!
how doing in .htaccess
file?
add .htaccess
file in document_root
rewriteengine on rewriterule ^admin/users/user/([^/]+)/? index.php?pagename=user&user_login=$1 [dpi,l]
this assumes mod_rewrite both installed and activated htaccess files.
Comments
Post a Comment