uuuvps:香港VPS低至97元/年,CN2+bgp网络,香港机房VPS优惠促销
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

我们的wp打开分类目录显示的链接默认是加上了/category/ 目录标志,非常的不美观,url非常的长,不利于url的SEO,网上多多方法,总结两种,一种是 WP No Category Base 插件,一种是手动编辑主题函数文件。
不管安装插件或者用代码可能会出现404页面,即%post_id%.html(本站设置的固定链接)的伪静态失效了!
解决方法:登录后台→设置→固定链接设置页面,随意改一下固定链接格式,然后再改回自己正常用的固定链接格式,可以解决这个bug,不行就反复多改几次。
方法一、WP No Category Base 插件
WP No Category Base 插件功能简单,就是仅仅为了去除 /category/ 目录标志,直接安装,不需要任何设置就可以使用。如果你的是新站,可以考虑去除/category/ 目录;如果你的是老站(也就是说搜索引擎已经收录了分类目录),使用这个插件后,注意做一下分类链接的301跳转。
方法二、非插件
不用插件来实现WordPress去掉分类链接中category目录,只需要将下面代码添加到你当前主题的 functions.php 文件中即可:
打开文件,移动到最尾部粘贴
//去除分类标志代码
add_action( ‘load-themes.php’, ‘no_category_base_resh_rules’);
add_action(‘created_category’, ‘no_category_base_resh_rules’);
add_action(‘edited_category’, ‘no_category_base_resh_rules’);
add_action(‘delete_category’, ‘no_category_base_resh_rules’);
function no_category_base_resh_rules() {
global $wp_rewrite;
$wp_rewrite -> flush_rules();
}
// register_deactivation_hook(FILE, ‘no_category_base_deactivate’);
// function no_category_base_deactivate() {
// remove_filter(‘category_rewrite_rules’, ‘no_category_base_rewrite_rules’);
// // We don’t want to insert our custom rules again
// no_category_base_resh_rules();
// }
// Remove category base
add_action(‘init’, ‘no_category_base_permastruct’);
function no_category_base_permastruct() {
global $wp_rewrite, $wp_version;
if (version_compare($wp_version, ‘3.4’, ‘<‘)) { // For pre-3.4 support $wp_rewrite -> extra_permastructs[‘category’][0] = ‘%category%’;
} else {
$wp_rewrite -> extra_permastructs[‘category’][‘struct’] = ‘%category%’;
}
}
// Add our custom category rewrite rules
add_filter(‘category_rewrite_rules’, ‘no_category_base_rewrite_rules’);
function no_category_base_rewrite_rules($category_rewrite) {
//var_dump($category_rewrite); // For Debugging
$category_rewrite = array();
$categories = get_categories(array(‘hide_empty’ => false));
foreach ($categories as $category) {
$category_nicename = $category -> slug;
if ($category -> parent == $category -> cat_ID)// recursive recursion
$category -> parent = 0;
elseif ($category -> parent != 0)
$category_nicename = get_category_parents($category -> parent, false, ‘/’, true) . $category_nicename;
$category_rewrite[‘(‘ . $category_nicename . ‘)/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$’] = ‘index.php?category_name=$matches[1]&feed=$matches[2]’;
$category_rewrite[‘(‘ . $category_nicename . ‘)/page/?([0-9]{1,})/?$’] = ‘index.php?category_name=$matches[1]&paged=$matches[2]’;
$category_rewrite[‘(‘ . $category_nicename . ‘)/?$’] = ‘index.php?category_name=$matches[1]’;
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_category_base = get_option(‘category_base’) ? get_option(‘category_base’) : ‘category’;
$old_category_base = trim($old_category_base, ‘/’);
$category_rewrite[$old_category_base . ‘/(.*)$’] = ‘index.php?category_redirect=$matches[1]’;
//var_dump($category_rewrite); // For Debugging
return $category_rewrite;
}
// Add ‘category_redirect’ query variable
add_filter(‘query_vars’, ‘no_category_base_query_vars’);
function no_category_base_query_vars($public_query_vars) {
$public_query_vars[] = ‘category_redirect’;
return $public_query_vars;
}
// Redirect if ‘category_redirect’ is set
add_filter(‘request’, ‘no_category_base_request’);
function no_category_base_request($query_vars) {
//print_r($query_vars); // For Debugging
if (isset($query_vars[‘category_redirect’])) {
$catlink = trailingslashit(get_option(‘home’)) . user_trailingslashit($query_vars[‘category_redirect’], ‘category’);
status_header(301);
header(“Location: $catlink”);
exit();
}
return $query_vars;
}
不管安装插件或者用代码可能会出现404页面,即%post_id%.html(本站设置的固定链接)的伪静态失效了!
解决方法:登录后台→设置→固定链接设置页面,随意改一下固定链接格式,然后再改回自己正常用的固定链接格式,可以解决这个bug,不行就反复多改几次。
[主机测评]历史优惠活动内容
猜你可能想看的VPS
- Online→€1.99 月 C2350 4GB 内存 1TB 硬盘 不全球[VPS测评]
- 补货通知 anynode→CN2 GIA 线路 512M 套餐和 256全球[VPS测评]
- 搬瓦工 VPS 一键安装 Windows 系统教程WINDOWS
- 便宜 $2 月 512M 内存 10G SSD 1Gbps 不限流量 K全球[VPS测评]
- 特价补货 tmhhost→512M 1 核 20G 0.5T 流量 季付全球[VPS测评]
- 在 Ubuntu 系统下安装最新稳定版 qBittorrent全球[VPS测评]
- [ 黑五]PacificRack→$18.95 年 KVM-1GB 30全球[VPS测评]
- Kdatacenter→韩国 KVM-1GB 100GB SSD 500韩国VPS[主机]
- 如何快速创建个人独立博客并从中获益?独立服务器[U]
- 咖啡主机元旦洛杉矶高防/香港将军澳VPS八折优惠,月付16元起香港VPS[主机]
- RackNerd 8月底促销1.5G NVMe 硬盘 最高6T 流量 年全球[VPS测评]
- 用Google Adsense自动广告来赚更多的钱全球[VPS测评]
- steadcloud-2.99$ 月 1核512MB内存15GB硬盘 巴美国VPS[主机]
- BugetNode → 7G内存 70G储存 7T流量 荷兰高配鸡 月付全球[VPS测评]
- GigsGigsCloud新加坡大陆优化VPS上架全球[VPS测评]
- 2019圣诞: CloudCone 512 内存 30G SSD 3T流全球[VPS测评]
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- JGKVM活动钜惠:美国cn2,香港cmi,大带宽vps,三网直连,10美国VPS[主机]
- 什么是linux面板?常见的Linux控制面板有哪些?全球[VPS测评]
- 云计算拯救互联网巨头?全球[VPS测评]
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- 因搜包耽误员工下班,苹果将支付3050万美元赔款全球[VPS测评]
- HostKVM香港云地VPS,2核4G内存折后$8.4/月,30M大带宽香港VPS[主机]
- Centos7的firewall 防火墙如何设置端口转发?全球[VPS测评]
- 极光KVM:1核512M/50Mbps/BGP+CN2/美西vps/年付香港VPS[主机]
- 新华全媒+丨第六届全球跨境电商大会:跨境电商加快拓宽中国贸易新通道全球[VPS测评]
- 弘速科技:香港安畅CN2 GIA/弹性云服务器10元/月,2核1GB/2香港VPS[主机]
- 什么是Bootstrap?全球[VPS测评]
- RFCHost:1核1G洛杉矶vps/15GB空间/1TB流量/KVM/虚拟空间(主机)
- 易探云:独立IP香港云服务器租用,香港vps海外云主机BGP线路/CN2独立服务器[U]
转载请注明原文地址:http://140.238.13.167:12355/read-237459.html











