一个新网站需要结合SEO,才能做成一个优秀的网站,

◆◆◆ 关于WordPress的分类目录url中含有category的处理办法:

1,如果是新网站这些设置需要提前做,方便以后做SEO

1、修改固定链接设置

打开WP后台-设置-固定链接

自定义结构,可以依据对SEO友好设置url

温馨提示:在分类目录那一栏里写入英文半角的点,此时得需要你的网站是全新的,没有分类栏目和文章,这样才不会出错,如果已有文章,这样的方法会使你的文章和分类栏目不存在
2.借助Wordpress插件

使用插件“WP No Category Base”插件

3.WP No category Base 插件的主体代码插入到function.php中(不使用插件,只放代码在后台)

//去除分类标志代码
add_action( 'load-themes.php', 'no_category_base_refresh_rules');
add_action('created_category', 'no_category_base_refresh_rules');
add_action('edited_category', 'no_category_base_refresh_rules');
add_action('delete_category', 'no_category_base_refresh_rules');
function no_category_base_refresh_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_refresh_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;
}

 ◆◆◆WordPress会生成很多作者链接
   因为wp有一个作者归档的模板文件

  wordpress作者的相关函数调用代码

<?php the_author(); ?> 显示文章的作者
2.<?php the_author_description(); ?> 显示文章作者的描述(作者个人资料中的描述)
3.<?php the_author_login(); ?> 显示文章作者的登录名
4.<?php the_author_firstname(); ?> 显示文章作者的firstname(名)
5.<?php the_author_lastname(); ?> 显示文章作者的lastname(姓)
6.<?php the_author_nickname(); ?> 显示文章作者的昵称
7.<?php the_author_ID(); ?> 显示文章作者的ID号
8.<?php the_author_email(); ?> 显示文章作者的电子邮箱
9.<?php the_author_url(); ?> 显示文章作者的网站地址
10.<?php the_author_link (); ?>(添加于2.1版本) 显示一个以文章作者名为链接名,链接地址为文章作者的网址的链接。
11.<?php the_author_icq(); ?> (不推荐使用) 显示文章作者的icq
12.<?php the_author_aim(); ?> 显示文章作者的aim
13.<?php the_author_yim(); ?> 显示文章作者的yim
14.<?php the_author_msn(); ?> (不推荐使用) 显示文章作者的msn
15.<?php the_author_posts(); ?> 显示文章作者已发表文章的篇数
16.<?php the_author_posts_link(); ?> 显示一个链接到文章作者已发表文章列表的链接
17.<?php list_authors(); ?> (不推荐使用) 显示blog所有作者和他们的相关信息。完整函数如下:

1. 一个不错的解决方法是将WordPress作者存档链接中的用户名改为昵称。
修改方法如下:

/**
* 将WordPress作者存档链接中的用户名改为昵称
* https://www.wpdaxue.com/use-nickname-for-author-slug.html
*/
//使用昵称替换用户名,通过用户ID进行查询
add_filter( 'request', 'wpdaxue_request' );
function wpdaxue_request( $query_vars )
{
if ( array_key_exists( 'author_name', $query_vars ) ) {
global $wpdb;
$author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) );
if ( $author_id ) {
$query_vars['author'] = $author_id;
unset( $query_vars['author_name'] );
}
}
return $query_vars;
} //使用昵称替换链接中的用户名
add_filter( 'author_link', 'wpdaxue_author_link', 10, 3 );
function wpdaxue_author_link( $link, $author_id, $author_nicename )
{
$author_nickname = get_user_meta( $author_id, 'nickname', true );
if ( $author_nickname ) {
$link = str_replace( $author_nicename, $author_nickname, $link );
}
return $link;
}

如果不希望蜘蛛爬取这些链接:给作者链接添加nofollow

打开wp-includes/author-template.php
查找‘<a href="%1$s" title="%2$s">%3$s</a>',只需加个nofollow标签,例如:'<a href="%1$s" title="%2$s" rel="nofollow">%3$s</a>'

2.更改wordpress主题内的function.php文件,在php循环内增加如下代码:

//给 the_author_post_link 生成的链接加上 rel="nofollow"

add_filter('the_author_posts_link','cis_nofollow_the_author_posts_link');

function cis_nofollow_the_author_posts_link ($link) {

return str_replace('<a href=','<a rel="nofollow" href=', $link);

}

更改/移除WordPress作者存档页面的前缀“author”

3.可以在根目录下新建一个作者页面author.php  

  

  

 

如何去掉WordPress分类目录url链接中的category,如何处理生成的作者链接的更多相关文章

  1. 【面试题】如何去掉vue的url地址中的#号?及其原理?

    如何去掉vue的url地址中的#号?及其原理? 点击打开视频讲解更加详细 如何去掉vue的url地址中的#号? import Vue from 'vue'; import VueRouter from ...

  2. wordpress去掉导航栏链接中的category

    找到服务器目录下的functions..php文件,在末尾处添加如下内容即可. 路径:/htdocs/wp-content/themes/functions.php 要追加在functions.php ...

  3. 如何去掉wordpress网站url里面的index.php(Apache服务器)

    在wordpress根目录新建.htaccess文件,并拷贝以下代码保存即可. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase ...

  4. 通过修改源码,免插件实现wordpress去除链接中的category

    将以下代码加在主题目录的functions.php /** * 去除category */ add_action('load-themes.php', 'no_category_base_refres ...

  5. URL 链接中 井号#、问号?、连接符& 分别有什么作用?

    在一个 URL 中可以包含很多的内容,其中不仅仅是包含 26 个英文字母,10 个罗马数字,中文汉字,还可以拥有井号“#”.问号“?”.连接符“&”等三种最常见的符号,那么这些符号在网站中都有 ...

  6. 转载:URL链接中的不同用处

    ,井号:表示网页中的一个位置,被称之为锚点,常用于某个网页间不同位置的跳转,简单的说就是在一个网页中,URL 不变的情况下,通过添加"#buy"的字符在 URL 最后可以跳转到当前 ...

  7. 在WordPress后台菜单系统中添加Home链接

    在wordpress后台如果想打开前台的话,要想先把鼠标移动到左上角菜单,然后在下拉菜单中点击“查看站点”,很是麻烦,能不能在 WordPress 后台菜单系统中添加 Home 链接呢? 将下面代码复 ...

  8. URL 链接中的 UTM参数何定义?

    浏览网页或者点击广告的时候,细心的朋友们或者有关注浏览器地址栏的 URL 链接时,一定会发现 utm_source 或者与其类似的链接,那么链接中的这个UTM参数有什么用呢? UTM 为“Urchin ...

  9. 在nginx下去掉ci框架url中的index.php

    ci框架默认的url规则中带有应用的入口文件,例如: example.com/index.php/news/article/my_article 在以上URL中带有入口文件index.PHP,这样的U ...

  10. 截取URL链接中字段的方法

    第一个页面像第二个页面传参方法 location.href = "poster.html?" + "name=" + name + "&tim ...

随机推荐

  1. Java实现哈希表

    2.哈希表 2.1.哈希冲突 冲突位置,把数据构建为链表结构. 装载因子=哈希表中的元素个数 / (散列表)哈希表的长度 装载因子越大,说明链表越长,性能就越低,那么哈希表就需要扩容,把数据迁移到新的 ...

  2. wordpress自建博客站,在页脚添加网站总访问次数

    wordpress自建博客站,在页脚添加网站总访问次数 笔者使用的主题是 GeneratePress 版本:3.1.3 打开footer.php编辑 <div style="text- ...

  3. 【已解决】linux环境jps命令不显示进程

    2021-09-28 10:26:42 问题描述: 输入jps后不显示进程 解决办法 1. cd /tmp/hsperfdata_root/ 2. ls 如果是空的 3. rm -rf hsperfd ...

  4. C++设计模式 - 解析器模式(Interpreter)

    领域规则模式 在特定领域中,某些变化虽然频繁,但可以抽象为某种规则.这时候,结合特定领域,将问题抽象为语法规则,从而给出在该领域下的一般性解决方案. 典型模式 Interpreter Interpre ...

  5. MySQL数据库维护和改善性能

    备份数据   由于MySQL数据库是基于磁盘的文件,普通的备份系统和例程就能备份MySQL的数据.但是,由于这些文件总是处于打开和使用状态,普通的文件副本备份不一定总是有效.下面列出这个问题的可能解决 ...

  6. ET介绍——浅谈AI框架

    AI框架 1. 几种AI的设计 AI在游戏中很多,但是为什么大家总是感觉ai编写起来十分困难,我后来思考了一番,主要原因是使用的方法不当.之前大家编写ai主要有几种方案: a. 状态机 我是不知道谁想 ...

  7. Luogu P3294 背单词

    观前须知 本题解全部内容遵循CC BY-NC-SA 4.0 Deed原则 更好的观看体验 点这里 笔者的博客主页 正文 Luogu P3294 [SCOI2016]背单词 笔者在刷题的时候看到了这道好 ...

  8. #树状数组,CDQ分治#洛谷 4390 [BOI2007]Mokia 摩基亚

    题目 分析 考虑离线处理,那么询问区间和就可以转换为四个询问, CDQ分治按横坐标处理询问,树状数组维护前缀和就可以了 代码 #include <cstdio> #include < ...

  9. 2024-04-06:用go语言,给你两个非负整数数组 rowSum 和 colSum, 其中 rowSum[i] 是二维矩阵中第 i 行元素的和, colSum[j] 是第 j 列元素的和,换言之你

    2024-04-06:用go语言,给你两个非负整数数组 rowSum 和 colSum, 其中 rowSum[i] 是二维矩阵中第 i 行元素的和, colSum[j] 是第 j 列元素的和,换言之你 ...

  10. 网站优化之开启tomcat的gzip压缩传输特性

    本文于2015年底完成,发布在个人博客网站上. 考虑个人博客因某种原因无法修复,于是在博客园安家,之前发布的文章逐步搬迁过来. 基于tomcat 8.0.x版本的文档,可以了解到tomcat支持基于g ...