在您的中尝试此重写规则functions.php
function string_url_rewrite() {
global $wp_rewrite;
add_rewrite_tag(\'%pet-page%\', \'([^&]+)\');
//In the rewrite rule you need to enter page slug and page id
add_rewrite_rule(\'^Enter_Page_slug/([0-9]+)/?\', \'index.php?page_id=Enter_Page_ID&pet-page=$matches[1]\', \'top\');
$wp_rewrite->flush_rules(true);
}
add_action(\'init\', \'string_url_rewrite\', 10, 0);
现在您还需要在中更改URL的格式
anchor tag
. 例如,您以前的URL
http://www.example.com/my-account/view-pet/?pet-page=2
将此URL更改为
http://www.example.com/my-account/view-pet/2
获取的值
pet-page
使用以下方法
//Storing the value of \'pet-page\' in variable
$value = get_query_var( \'pet-page\' );
if($value){ //checking if variable has any value or not
echo \'This is the value \'.$value;
} else {
echo \'No Values\';
}
Note: 如果这不起作用,那么冲洗你的permalinks。为此,请访问
setting -> permalink
并保存更改。