您可以添加重写规则以改进URL的外观,同时保持相同的功能:
例如:
add_action(\'init\', \'custom_shop_param\');
function custom_shop_param() {
    add_rewrite_tag(\'%param%\',\'([^&]+)\');
    add_rewrite_rule(\'^shop/([^/]+)/?$\',\'index.php?page=shop¶m=$matches[1]\',\'top\');
}
 当您访问时
http://site/wp/shop/{somevalue} 进行以下操作的值
/shop/ URL的一部分将被匹配并存储在查询变量中
param 通过使用
add_rewrite_tag, 这个
$matches[1] 变量为表达式的第一个匹配组保存正则表达式的值,
http://site/wp/shop/discountproduct 相当于
param=discountproduct 可通过访问
query_vars 作为请求的一部分:
//somewhere in your code....
function parse_shop_request() {
    global $wp_query;
    if ( isset($wp_query->query_vars[\'param\']) ) {
         //do something with $wp_query->query_vars[\'param\']
    }
}
 您也可以使用
get_query_var(\'param\') 检索查询变量。
如果http://domain/wp/shop/value 在该URL深度与产品、类别或其他页面发生冲突或可能发生冲突,然后可以进一步扩展重写规则:
http://site/wp/shop/get/value
add_action(\'init\', \'custom_shop_param\');
function custom_shop_param() {
    add_rewrite_tag(\'%param%\',\'([^&]+)\');
    add_rewrite_rule(\'^shop/get/([^/]+)/?$\',\'index.php?page=shop¶m=$matches[1]\',\'top\');
}
 当然,更换
/get/ 用任何适合你的措辞或上下文的东西。
您甚至可以:
add_action(\'init\', \'custom_shop_param\');
function custom_shop_param() {
    add_rewrite_tag(\'%param%\',\'([^&]+)\');
    add_rewrite_rule(\'^shop/?param=([^/]+)$\',\'index.php?page=shop¶m=$matches[1]\',\'top\');
}
 有用的链接: