下面是一个向WordPress添加自定义重写规则的示例。例如,您有一个链接http://website.com/1/ WordPress内部将其解释为http://website.com?tl=1
但对于tl 你提到过,我不确定你的设置是什么。所以我想tl 正在您的系统中工作。因为WP默认参数为p 对于页面id
您可以尝试在主题函数中使用以下过滤器。php或插件
以下仅在permalinks打开时有效。否则,无效。这意味着settings -> permalinks, 如果您选择Plain, 然后WordPress将显示没有漂亮URL的查询。它被视为turned off.否则,如果您选择其他选项,如Post Name 然后WordPress将接受帖子名称作为URL,例如https://examples.com/sample-post/如果正在启用(或打开),则为So。然后将使用重写系统。下面的过滤器与WordPress重写系统配合使用。
有时我们会使用其他synonym 喜欢Enable permalinks, Disable permalinks. 它也有同样的含义。
这里,假设放置在functions.php
add_action( \'init\', \'q363603_add_custom_rewrites\' );
function q363603_add_custom_rewrites() {
// take numbers to the query tl=numbers
add_rewrite_rule(\'([0-9])+/?$\', \'index.php?tl=$matches[1]\', \'top\');
}
add_filter(\'query_vars\', \'q363603_add_custom_queryvars\' );
function q363603_add_custom_queryvars( $qvars ) {
// ask WordPress to allow this query parameter
$qvars[] = \'tl\';
return $qvars;
}
已编辑:添加
permalinks turning on/off explanation