优化WordPress分类链接及WP-No-Category-Base的卸载办法

默许状况下,WordPress分类的永世链接是这样的比方本站的技术文章分类。

exehack.net/category/my-article/

假如能把两头那段Category去掉,是不是更美观切更利于SEO优化呢:

exehack.net/my-my-article/

去除category的成果图:







小遍发现了二种办法:

1.开端本站就是启用的WP No  Category Base插件,应用它地将Wordpress强迫退出的分类链接格局去掉。
插件特性:

1.将一级目录和二级目录永世链接格局优化为
exehack.net/my-my-article/
exehack.net/software/black-soft

以下是官网给出的这款插件的引见:

1. 应用十分简略-简直不会增加任何额定累赘
2. 工作十分顺畅-无需任何设置
3. 无需修正wordpress 文件
4. 不需求任何其余插件就能工作
5. 与sitemap插件兼容
6. 对多级分类同样起作用。

PS:以上说法都没错,可是这苦逼的作者为什么不加上一条”该插件应用后无奈停用或卸载”否则货照成网站文章无奈拜访”。

置信大家都有同感为什么明明是去除分类的category和文章页的url有什么关系?

这款插件确实很不错,可是小编十分厌恶流氓的插件,可是确无奈停用.

通过小编的苦苦寻觅终于发现了而后处理停用WP-No-Category-Base插件后文章页无奈关上的办法。

办法十分简略:

1.把【固定衔接】改为【默许】形态,而后,封闭【WP NO category base】插件
2.再改回之前的URL方式就能够了。
3.最初你就可卸载掉该插件了。

既然是要卸载掉【WP NO category base】插件的话小编早已找到新的办法来去除分类页面的category。
否则文章全副无奈拜访全是404谬误页面大家辛辛劳苦运营起来的网站岂不是全毁了。

2.所以这里就引见另外一种办法经过在functions.php增加如下代码来进行去除Category

代码如下:

PHP Code复制内容到剪贴板

  1. //去除分类   
  2. add_action( 'load-themes.php',  'no_category_base_refresh_rules');   
  3. add_action('created_category''no_category_base_refresh_rules');   
  4. add_action('edited_category''no_category_base_refresh_rules');   
  5. add_action('delete_category''no_category_base_refresh_rules');   
  6. function no_category_base_refresh_rules() {   
  7.     global $wp_rewrite;   
  8.     $wp_rewrite -> flush_rules();   
  9. }   
  10. // register_deactivation_hook(__FILE__, 'no_category_base_deactivate');   
  11. // function no_category_base_deactivate() {   
  12. //     remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');   
  13. //     // We don't want to insert our custom rules again   
  14. //     no_category_base_refresh_rules();   
  15. // }   
  16. // Remove category base   
  17. add_action('init', 'no_category_base_permastruct');  
  18. function no_category_base_permastruct() {  
  19.     global $wp_rewrite, $wp_version;  
  20.     if (version_compare($wp_version, '3.4', '<')) {  
  21.         // For pre-3.4 support  
  22.         $wp_rewrite -> extra_permastructs['category'][0] = '%category%';  
  23.     } else {  
  24.         $wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';  
  25.     }  
  26. }  
  27. // Add our custom category rewrite rules  
  28. add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');  
  29. function no_category_base_rewrite_rules($category_rewrite) {  
  30.     //var_dump($category_rewrite); // For Debugging  
  31.     $category_rewrite = array();  
  32.     $categories = get_categories(array('hide_empty' => false));  
  33.     foreach ($categories as $category) {  
  34.         $category_nicename = $category -> slug;  
  35.         if ($category -> parent == $category -> cat_ID)// recursive recursion  
  36.             $category -> parent = 0;  
  37.         elseif ($category -> parent != 0)  
  38.             $category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename;  
  39.         $category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';  
  40.         $category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';  
  41.         $category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';  
  42.     }  
  43.     // Redirect support from Old Category Base  
  44.     global $wp_rewrite;  
  45.     $old_category_base = get_option('category_base') ? get_option('category_base') : 'category';  
  46.     $old_category_base = trim($old_category_base, '/');  
  47.     $category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';  
  48.       
  49.     //var_dump($category_rewrite); // For Debugging  
  50.     return $category_rewrite;  
  51. }  
  52.       
  53. // Add 'category_redirect' query variable  
  54. add_filter('query_vars', 'no_category_base_query_vars');  
  55. function no_category_base_query_vars($public_query_vars) {  
  56.     $public_query_vars[] = 'category_redirect';  
  57.     return $public_query_vars;  
  58. }  
  59.       
  60. // Redirect if 'category_redirect' is set  
  61. add_filter('request', 'no_category_base_request');  
  62. function no_category_base_request($query_vars) {  
  63.     //print_r($query_vars); // For Debugging  
  64.     if (isset($query_vars['category_redirect'])) {  
  65.         $catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category');   
  66.         status_header(301);   
  67.         header("Location: $catlink");   
  68.         exit();   
  69.     }   
  70.     return $query_vars;   
  71. }  

以上就是安达网络工作室关于《优化WordPress分类链接及WP-No-Category-Base的卸载方法》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 分类链接
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
wordpress文章题目为空时其它内容替代的办法

在WordPress中时常存在某些文章不需求题目的状况,特地是在一些集体网站,他们经常应用一些不需求题目的pos...

Wordpress插件的应用

要害字形容:应用 插件 Wordpress 能够 文件 需求 网站 目录 网友 Wordpress 的主题能够让你的 Wordpress ...

WordPress站点完成分类目录订阅性能实例

WordPress有着比拟弱小的分类机制,包括文章分类、标签等,弱小的分类机制能够用来完成门户网站的相似二级频...

是 WordPress 让 PHP 更盛行了 而不是框架

Tiobe Index(编程言语世界排名指数),是一个显示各种编程言语的绝对盛行趋向的排名,开端于 2001 年,每...

WordPress评论中制止HTML代码显示的办法

本文实例讲述了WordPress评论中制止HTML代码显示的办法。分享给大家供大家参考。详细剖析如下: 应用WordPr...

详解WordPress开发中wp_title()函数的用法

wp_title 函数在 WordPress 中是用来显示文章、页面、分类等等等等题目的一个函数,但在首页索引,该函数将...

需求提交

客服服务

亿鸽在线客服系统