有的时候,当我们创建页面时用的slug,会跟自定义文章类型的slug,甚至是自定义文章类型的post_type名称冲突。会导致wordpress路由到不希望展示的那个页面上。
解决方法:
/*
make pages slug have priority over any other taxonomies like custom-post, post or category
You will need to enable verbose page rules, which make sure that all pages are explicitly defined (instead of using a generic rule).
*/
add_action('init', 'wpse16902_init');
function wpse16902_init()
{
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}
add_filter('page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules');
function wpse16902_collect_page_rewrite_rules($page_rewrite_rules)
{
$GLOBALS['wpse16902_page_rewrite_rules'] = $page_rewrite_rules;
return array();
}
add_filter('rewrite_rules_array', 'wspe16902_prepend_page_rewrite_rules');
function wspe16902_prepend_page_rewrite_rules($rewrite_rules)
{
return $GLOBALS['wpse16902_page_rewrite_rules'] + $rewrite_rules;
}
评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。