月神科技:香港沙田机房vps优惠码首月8折,1核/1G/40G SSD/500G/10Mbps,24元
|
![]() |
![]() |
![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |
我们的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
- TabbyCloud:香港BGP云服务器,1核/1GB/20GB空间/2 虚拟空间(主机)
- HostKvm:洛杉矶云主机/香港云主机八折优惠,大带宽,月付5.2美元 香港VPS[主机]
- aoyoyun:傲游主机/傲游vps/傲游云,香港vps,60M大带宽, WINDOWS
- 自适应bootstrap左侧导航可关闭 全球[VPS测评]
- CentOS 7.x 系统安装和配置redis-7.0.4集群 全球[VPS测评]
- BBR对比BBR2BBRPLUSBBR2CAKE锐速哪个效果好 全球[VPS测评]
- 做跨境电商一个月都有多少收入? 全球[VPS测评]
- 向日葵-漏洞科普:海外云服务器三种漏洞修复方法快收藏起来! 全球[VPS测评]
- 邢志宏:加快推动高质量建设跨境电商综试区起势成势 全球[VPS测评]
- 厘米云,江苏移动100G高防云服务器,4核4G内存20M带宽79元/月 全球[VPS测评]
- CMCUCT:2核2GB/20GB香港ntt线路vps 6TB流量/1G 香港VPS[主机]
- 野草云服务器怎么样?香港CN2+BGP带宽30M月付19元 香港VPS[主机]
- 轻云互联,香港美国vps终身8.8折17元/月起,cn2直连线路,50G 美国VPS[主机]
- 亿速云11.11上云狂欢节活动:2核4G国内/香港云服务器,价格999元 香港VPS[主机]
- hosthatch:香港/芝加哥/伦敦等11机房VPS低至$17.5/年 香港VPS[主机]
- 腾讯云限时秒杀改版:轻量应用服务器2核4G8M仅598元/年,增香港/新 香港VPS[主机]
- 孤狼云:香港CN2/美国CN2 VPS首月特价¥6.8元;香港虚拟主机仅 美国VPS[主机]
- 腾讯云轻量应用服务器128元/年,香港免备案vps/30M大带宽/100 香港VPS[主机]
- 香港云服务器性价比高:香港云服务器哪家便宜 香港VPS[主机]
- 酷锐云:元旦钜惠_美国CN2VPS低至20元/月_1核2G香港云主机低至 美国VPS[主机]
- 酷锐云:香港安畅机房4H/4G/60G/20Mbps,45元/月;香港C 香港VPS[主机]
- 柚子互联:美国洛杉矶CN2 vps,防御100G/带宽10M,28元/月 美国VPS[主机]
- 特网云:新上香港高防云主机,金盾防护无视CC,恶意流量攻击防护 香港VPS[主机]
- 腾讯云香港服务器2核4G30M仅804元/年,2412元/3年;国内轻量 香港VPS[主机]
- 易探云:香港免备案云服务器年付6.8折,2核4G5M+10G数据盘仅79 香港VPS[主机]
- 常见的CN2,GIA,CIA 各个网络线路解释 全球[VPS测评]
- wikihost,微基主机服务,100M带宽香港tudcloud,5G防 香港VPS[主机]
- tudcloud,香港沙田大带宽vps特惠7折,CN2+BGP直连,10 香港VPS[主机]
- hostkvm怎么样?香港云vps 带宽30M 月付6美元 香港VPS[主机]
- 麻花云怎么样?安徽移动VPS月付29元 香港VPS 2M月付21元 香港VPS[主机]
转载请注明原文地址: http://140.238.13.167:12355/read-252357.html











