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-code">Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-1">1 Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-3">3 Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-5">5 Crayon-num" data-line="Crayon-5c891d52eb9ec266207631-7">7 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">; 方法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">
|