WordPress中去掉固定链接中的category

前端之家收集整理的这篇文章主要介绍了WordPress中去掉固定链接中的category前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

wordpress默认情况下设置固定链接分类页面是有category路径的。出于SEO优化的考虑,网站的链接层次多,不利于蜘蛛的抓取,也就是说链接越简洁越好,链接的路径越少越好。在百度优化指南中,百度一直是建议站长们使用浅表的层次结构。

下面我们讲解一下wordpress建站中去掉固定链接中的category的方法

方法1:切换到主题目录,打开functions.PHP文件添加如下代码,然后到wordpress后台中设置的地方,点击固定链接,保存即可生效。

Crayon-5c891d52eb9ec266207631" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9ec266207631-2">2
Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9ec266207631-4">4
Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9ec266207631-6">6
Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9ec266207631-8">8
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d52eb9ec266207631-1">Crayon-c">/**
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9ec266207631-2">Crayon-c"> * 去除固定链接中的/category/路径,记得在后台保存一次固定链接
Crayon-line" id="Crayon-5c891d52eb9ec266207631-3">Crayon-c"> */
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9ec266207631-4">Crayon-e">add_actionCrayon-sy">(Crayon-s">'init'Crayon-sy">,Crayon-h"> Crayon-s">'jacky_no_category'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9ec266207631-5">Crayon-t">functionCrayon-h"> Crayon-e">jacky_no_categoryCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9ec266207631-6">Crayon-h"> Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">wp_rewriteCrayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9ec266207631-7">Crayon-h"> Crayon-sy">$Crayon-v">wp_rewriteCrayon-h"> Crayon-h"> Crayon-v">extra_permastructsCrayon-sy">[Crayon-s">'category'Crayon-sy">]Crayon-sy">[Crayon-s">'struct'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'%category%'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9ec266207631-8">Crayon-sy">}

方法2:基于插件WP No Category Base上的代码,切换到主题目录,打开functions.PHP文件添加如下代码,然后到wordpress后台中设置的地方,点击固定链接,保存即可生效。

Crayon-5c891d52eb9f7838060802" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-2">2
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-4">4
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-6">6
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-8">8
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-10">10
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-12">12
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-14">14
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-16">16
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-18">18
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-20">20
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-21">21
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-22">22
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-23">23
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-24">24
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-25">25
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-26">26
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-27">27
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-28">28
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-29">29
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-30">30
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-31">31
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-32">32
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-33">33
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-34">34
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-35">35
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-36">36
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-37">37
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-38">38
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-39">39
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-40">40
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-41">41
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-42">42
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-43">43
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-44">44
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-45">45
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-46">46
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-47">47
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-48">48
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-49">49
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-50">50
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-51">51
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-52">52
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-53">53
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-54">54
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-55">55
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-56">56
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-57">57
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-58">58
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-59">59
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-60">60
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-61">61
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-62">62
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-63">63
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-64">64
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-65">65
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-66">66
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-67">67
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-68">68
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-69">69
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-70">70
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-71">71
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-72">72
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-73">73
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-74">74
Crayon-num" data-line="Crayon-5c891d52eb9f7838060802-75">75
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9f7838060802-76">76
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d52eb9f7838060802-1">Crayon-c">/**
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-2">Crayon-c"> * 去除固定链接中的/category/路径,添加后在后台保存一次固定链接
Crayon-line" id="Crayon-5c891d52eb9f7838060802-3">Crayon-c"> * 基于 WP No Category Base 插件
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-4">Crayon-c"> */
Crayon-line" id="Crayon-5c891d52eb9f7838060802-5">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-6">Crayon-e">add_actionCrayon-sy">(Crayon-h"> Crayon-s">'load-themes.PHP'Crayon-sy">,Crayon-h">Crayon-s">'no_category_base_refresh_rules'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-7">Crayon-e">add_actionCrayon-sy">(Crayon-s">'created_category'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_refresh_rules'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-8">Crayon-e">add_actionCrayon-sy">(Crayon-s">'edited_category'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_refresh_rules'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-9">Crayon-e">add_actionCrayon-sy">(Crayon-s">'delete_category'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_refresh_rules'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-10">Crayon-t">functionCrayon-h"> Crayon-e">no_category_base_refresh_rulesCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d52eb9f7838060802-11">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">wp_rewriteCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-12">Crayon-h">Crayon-sy">$Crayon-v">wp_rewriteCrayon-h"> Crayon-h"> Crayon-e">flush_rulesCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-13">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-14">Crayon-h">
Crayon-line" id="Crayon-5c891d52eb9f7838060802-15">Crayon-c">// register_deactivation_hook(__FILE__,'no_category_base_deactivate');
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-16">Crayon-c">// function no_category_base_deactivate() {
Crayon-line" id="Crayon-5c891d52eb9f7838060802-17">Crayon-c">//remove_filter('category_rewrite_rules','no_category_base_rewrite_rules');
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-18">Crayon-c">//// We don't want to insert our custom rules again
Crayon-line" id="Crayon-5c891d52eb9f7838060802-19">Crayon-c">//no_category_base_refresh_rules();
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-20">Crayon-c">// }
Crayon-line" id="Crayon-5c891d52eb9f7838060802-21">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-22">Crayon-c">// Remove category base
Crayon-line" id="Crayon-5c891d52eb9f7838060802-23">Crayon-e">add_actionCrayon-sy">(Crayon-s">'init'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_permastruct'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-24">Crayon-t">functionCrayon-h"> Crayon-e">no_category_base_permastructCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d52eb9f7838060802-25">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">wp_rewriteCrayon-sy">,Crayon-h"> Crayon-sy">$Crayon-v">wp_versionCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-26">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">version_compareCrayon-sy">(Crayon-sy">$Crayon-v">wp_versionCrayon-sy">,Crayon-h"> Crayon-s">'3.4'Crayon-sy">,Crayon-h"> Crayon-s">'<'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d52eb9f7838060802-27">Crayon-h">Crayon-c">// For pre-3.4 support
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-28">Crayon-h">Crayon-sy">$Crayon-v">wp_rewriteCrayon-h"> Crayon-h"> Crayon-v">extra_permastructsCrayon-sy">[Crayon-s">'category'Crayon-sy">]Crayon-sy">[Crayon-cn">0Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'%category%'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-29">Crayon-h">Crayon-sy">}Crayon-h"> Crayon-st">elseCrayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-30">Crayon-h">Crayon-sy">$Crayon-v">wp_rewriteCrayon-h"> Crayon-h"> Crayon-v">extra_permastructsCrayon-sy">[Crayon-s">'category'Crayon-sy">]Crayon-sy">[Crayon-s">'struct'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'%category%'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-31">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-32">Crayon-sy">}
Crayon-line" id="Crayon-5c891d52eb9f7838060802-33">Crayon-c">// Add our custom category rewrite rules
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-34">Crayon-e">add_filterCrayon-sy">(Crayon-s">'category_rewrite_rules'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_rewrite_rules'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-35">Crayon-t">functionCrayon-h"> Crayon-e">no_category_base_rewrite_rulesCrayon-sy">(Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-36">Crayon-h">Crayon-c">//var_dump($category_rewrite); // For Debugging
Crayon-line" id="Crayon-5c891d52eb9f7838060802-37">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-38">Crayon-h">Crayon-sy">$Crayon-v">category_rewriteCrayon-h"> Crayon-o">=Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-39">Crayon-h">Crayon-sy">$Crayon-v">categoriesCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_categoriesCrayon-sy">(Crayon-t">arrayCrayon-sy">(Crayon-s">'hide_empty'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-t">falseCrayon-sy">)Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-40">Crayon-h">Crayon-st">foreachCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-e">categories Crayon-st">asCrayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d52eb9f7838060802-41">Crayon-h">Crayon-sy">$Crayon-v">category_nicenameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-v">slugCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-42">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-r">parentCrayon-h"> Crayon-o">==Crayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-v">cat_IDCrayon-sy">)Crayon-c">// recursive recursion
Crayon-line" id="Crayon-5c891d52eb9f7838060802-43">Crayon-h">Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-r">parentCrayon-h"> Crayon-o">=Crayon-h"> Crayon-cn">0Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-44">Crayon-h">Crayon-st">elseifCrayon-h"> Crayon-sy">(Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-r">parentCrayon-h"> Crayon-o">!=Crayon-h"> Crayon-cn">0Crayon-sy">)
Crayon-line" id="Crayon-5c891d52eb9f7838060802-45">Crayon-h">Crayon-sy">$Crayon-v">category_nicenameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_category_parentsCrayon-sy">(Crayon-sy">$Crayon-v">categoryCrayon-h"> Crayon-h"> Crayon-r">parentCrayon-sy">,Crayon-h"> Crayon-t">falseCrayon-sy">,Crayon-h"> Crayon-s">'/'Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">category_nicenameCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-46">Crayon-h">Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">[Crayon-s">'('Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-sy">_nicenameCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">')/(?:Feed/)?(Feed|rdf|RSS|RSS2|atom)/?$'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'index.PHP?category_name=$matches[1]&Feed=$matches[2]'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-47">Crayon-h">Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">[Crayon-s">'('Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-sy">_nicenameCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">')/page/?([0-9]{1,})/?$'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'index.PHP?category_name=$matches[1]&paged=$matches[2]'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-48">Crayon-h">Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">[Crayon-s">'('Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-sy">$Crayon-v">categoryCrayon-sy">_nicenameCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">')/?$'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'index.PHP?category_name=$matches[1]'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-49">Crayon-h">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-50">Crayon-h">Crayon-c">// Redirect support from Old Category Base
Crayon-line" id="Crayon-5c891d52eb9f7838060802-51">Crayon-h">Crayon-m">globalCrayon-h"> Crayon-sy">$Crayon-v">wp_rewriteCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-52">Crayon-h">Crayon-sy">$Crayon-v">old_category_baseCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_optionCrayon-sy">(Crayon-s">'category_base'Crayon-sy">)Crayon-h"> Crayon-sy">?Crayon-h"> Crayon-e">get_optionCrayon-sy">(Crayon-s">'category_base'Crayon-sy">)Crayon-h"> Crayon-o">:Crayon-h"> Crayon-s">'category'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-53">Crayon-h">Crayon-sy">$Crayon-v">old_category_baseCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">trimCrayon-sy">(Crayon-sy">$Crayon-v">old_category_baseCrayon-sy">,Crayon-h"> Crayon-s">'/'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-54">Crayon-h">Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">[Crayon-sy">$Crayon-v">old_categoryCrayon-sy">_baseCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-s">'/(.*)$'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'index.PHP?category_redirect=$matches[1]'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-55">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-56">Crayon-h">Crayon-c">//var_dump($category_rewrite); // For Debugging
Crayon-line" id="Crayon-5c891d52eb9f7838060802-57">Crayon-h">Crayon-st">returnCrayon-h"> Crayon-sy">$Crayon-v">category_rewriteCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-58">Crayon-sy">}
Crayon-line" id="Crayon-5c891d52eb9f7838060802-59">Crayon-c">// Add 'category_redirect' query variable
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-60">Crayon-e">add_filterCrayon-sy">(Crayon-s">'query_vars'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_query_vars'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-61">Crayon-t">functionCrayon-h"> Crayon-e">no_category_base_query_varsCrayon-sy">(Crayon-sy">$Crayon-v">public_query_varsCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-62">Crayon-h">Crayon-sy">$Crayon-v">public_query_varsCrayon-sy">[Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'category_redirect'Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-63">Crayon-h">Crayon-st">returnCrayon-h"> Crayon-sy">$Crayon-v">public_query_varsCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-64">Crayon-sy">}
Crayon-line" id="Crayon-5c891d52eb9f7838060802-65">Crayon-c">// Redirect if 'category_redirect' is set
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-66">Crayon-e">add_filterCrayon-sy">(Crayon-s">'request'Crayon-sy">,Crayon-h"> Crayon-s">'no_category_base_request'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-67">Crayon-t">functionCrayon-h"> Crayon-e">no_category_base_requestCrayon-sy">(Crayon-sy">$Crayon-v">query_varsCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-68">Crayon-h">Crayon-c">//print_r($query_vars); // For Debugging
Crayon-line" id="Crayon-5c891d52eb9f7838060802-69">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">issetCrayon-sy">(Crayon-sy">$Crayon-v">query_varsCrayon-sy">[Crayon-s">'category_redirect'Crayon-sy">]Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-70">Crayon-h">Crayon-sy">$Crayon-v">catlinkCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">trailingslashitCrayon-sy">(Crayon-e">get_optionCrayon-sy">(Crayon-s">'home'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">.Crayon-h"> Crayon-e">user_trailingslashitCrayon-sy">(Crayon-sy">$Crayon-v">query_varsCrayon-sy">[Crayon-s">'category_redirect'Crayon-sy">]Crayon-sy">,Crayon-h"> Crayon-s">'category'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-71">Crayon-h">Crayon-e">status_headerCrayon-sy">(Crayon-cn">301Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-72">Crayon-h">Crayon-e">headerCrayon-sy">(Crayon-s">"Location: $catlink"Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d52eb9f7838060802-73">Crayon-h">Crayon-e">exitCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-74">Crayon-h">Crayon-sy">}
Crayon-line" id="Crayon-5c891d52eb9f7838060802-75">Crayon-h">Crayon-st">returnCrayon-h"> Crayon-sy">$Crayon-v">query_varsCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9f7838060802-76">Crayon-sy">}

方法3:基于伪静态,主机使用linux系统的用户,可以将带有category的链接重定向至没有它的链接,通过编写.htaccess的301重定向规则

Crayon-5c891d52eb9fa557614109" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">.htaccess
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d52eb9fa557614109-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d52eb9fa557614109-2">2
Crayon-num" data-line="Crayon-5c891d52eb9fa557614109-3">3
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d52eb9fa557614109-1">Crayon-e">RewriteEngine Crayon-e">On
Crayon-line Crayon-striped-line" id="Crayon-5c891d52eb9fa557614109-2">Crayon-v">RewriteBaseCrayon-h"> Crayon-o">/
Crayon-line" id="Crayon-5c891d52eb9fa557614109-3">Crayon-v">RewriteRuleCrayon-h"> Crayon-o">^Crayon-v">categoryCrayon-o">/Crayon-sy">(Crayon-sy">.Crayon-o">+Crayon-sy">)Crayon-sy">$Crayon-h"> Crayon-v">httpCrayon-o">:Crayon-c">//www.youdomain.com/$1 [R=301,L]

原文链接:https://www.f2er.com/wordpress/238517.html

猜你在找的wordpress相关文章