我在互联网上钓鱼寻求解决方案,尝试了一个或两个插件从wordpress网址中删除/ category /。
虽然其中一些插件不错,但类别link仍显示在/ category /。
此外,我还尝试在永久链接设置的类别基本选项中放入./。
有人知道我该怎么做才能像php搜索和替换之类的东西吗?
http://wordpress.org/extend/plugins/wp-no-category-base/,并且它不会更改永久链接,因此删除它会毫无问题地还原结构。而且您不必更改核心文件。
更清洁的解决方案:
add_filter('user_trailingslashit', 'remcat_function');
function remcat_function($link) {
return str_replace("/category/", "/", $link);
}
add_action('init', 'remcat_flush_rules');
function remcat_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter('generate_rewrite_rules', 'remcat_rewrite');
function remcat_rewrite($wp_rewrite) {
$new_rules = array('(.+)/page/(.+)/?' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2));
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
使用WordPress 3.9.1(本文的最新版本),我只是在主题的functions.php
中添加了一行
$wp_rewrite->add_permastruct('category_base', '%category%');
然后我打开设置>永久链接并点击保存。这似乎刷新了永久链接缓存并使之工作。
https://wordpress.org/plugins/no-category-base-wpml/是一个可解决问题并与WordPress当前版本兼容的插件。