WordPress网站做SEO优化时,内链是一个很重要的因素,而我们平时都是手动为文章添加内链,这样会牺牲一些时间,其实我们可以让网站自动为文章生成标签,并且为标签自动添加内链。以前有一款插件 WP Keyword Link ,但是刚才没搜索到,其实我们还可以使用纯代码实现这个功能。
它的用途是在你写完这篇文章发布的时候,自动检测你这篇文章中有的关键字,然后把这个关键字转成标签给你添加进去,这个貌似需要在后台发布文章才可以生效,也可以在前台编辑完文章发布,然后到后台再发布一遍。
add_action('save_post', 'auto_add_tags');
function auto_add_tags()
{
$tags = get_tags(array('hide_empty' => false));
$post_id = get_the_ID();
$post_content = get_post($post_id)->post_content;
if ($tags) {
foreach ($tags as $tag) {
// 如果文章内容出现了已使用过的标签,自动添加这些标签
if (strpos($post_content, $tag->name) !== false) {
wp_set_post_tags($post_id, $tag->name, true);
}
}
}
}它的用途就是你在写这篇文章的时候,如果添加了标签,它会自动把文章内含有标签的字添加成内链。
//WordPress文章关键词自动内链 大白博客
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tag_link($content){
$match_num_from = 1; //一个标签少于几次不链接
$match_num_to = 1; //一个标签最多链接几次
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
//链接代码
$cleankeyword = stripslashes($keyword);
$url = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('更多关于 %s 的文章-大白博客'))."\"";
$url .= ' target="_blank"';
$url .= ">".addcslashes($cleankeyword, '$')."</a>";
$limit = rand($match_num_from,$match_num_to);
//不链接代码
$content = preg_replace( '|(<a[^>]+>)(.*)<pre.*?>('.$ex_word.')(.*)<\/pre>(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tag_link',1);直接放主题目录下functions.php文件里面。
]]>[acc status="close" title="代码"]
<style>
.advertise-container {
width: 100%;
height: 100px;
overflow: hidden;
position: relative;
text-align: center;
}
.advertise-container .advertise-item {
width: 100%;
height: 100px;
position: absolute;
top: 0;
left: 0;
}
.advertise-container a {
display: inline-block;
width: 100%;
height: 100%;
line-height: 100px;
color: #000;
font-weight: bold;
text-decoration: none;
font-size: 24px;
animation: pulse 2s ease infinite;
background: transparent;
}
@keyframes pulse {
0% {
color: #000;
}
50% {
color: #f00;
}
100% {
color: #000;
}
}
</style>
<div class="advertise-container">
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位1</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位2</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位3</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位4</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位5</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位6</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位7</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位8</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位9</div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item">广告位10</div>
</a>
</div>
<script>
var advertise = document.querySelectorAll('.advertise-item');
var index = 0;
setInterval(function() {
advertise.forEach(function(item) {
item.style.display = 'none';
})
if (index >= advertise.length) {
index = 0;
}
advertise[index].style.display = 'block';
index++;
}, 2000)
</script>[/acc]
图片版
[acc status="close" title="代码"]
<style>
.advertise-container {
width: 100%;
height: 100px;
overflow: hidden;
position: relative;
}
.advertise-container .advertise-item {
width: 100%;
height: 100px;
position: absolute;
top: 0;
left: 0;
object-fit: cover;
}
.advertise-container a {
display: inline-block;
width: 100%;
height: 100%;
line-height: 100px;
color: #000;
font-weight: bold;
text-decoration: none;
font-size: 24px;
animation: pulse 2s ease infinite;
background: transparent;
text-align: center;
}
.advertise-container img {
width: 100%;
height: 100%;
}
@keyframes pulse {
0% {
color: #000;
}
50% {
color: #f00;
}
100% {
color: #000;
}
}
</style>
<div class="advertise-container">
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位1"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="图片链接" alt="广告位2"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="图片链接" alt="广告位3"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="图片链接" alt="广告位4"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位5"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位6"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位7"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位8"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位9"></div>
</a>
<a href="https://www.baidu.com" target="_blank">
<div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位10"></div>
</a>
</div>
<script>
var advertise = document.querySelectorAll('.advertise-item');
var index = 0;
setInterval(function() {
advertise.forEach(function(item) {
item.style.display = 'none';
})
if (index >= advertise.length) {
index = 0;
}
advertise[index].style.display = 'block';
index++;
}, 2000)
</script>[/acc]
放在任意侧边栏即可

首先在主题目录下创建func.php文件,有的人可能已经有此文件了。
在func.php添加如下代码即可
[acc status="close" title="php代码"]
<?php
add_action('wp_head', 'zibll_Add_ons_newindex');
function zibll_Add_ons_newindex() {
if(is_home()){
?>
<!--新首页开始-->
<div id="page-wrapper">
<div class="home-banner por">
<section class="section" style="height: calc(100vh - 220px);max-height: 600px;">
<div class="video-wrapper">
<video autoplay="" playsinline="" loop="" muted="" src="https://zsg-1251454718.cos.ap-beijing.myqcloud.com/%E8%AE%B0%E5%BD%95%E7%AC%94%E8%AE%B0.mp4">
</video>
</div>
<div class="video-overlay">
</div>
</section>
<div class="wrapper poa" style="top: 20%;">
<div class="home-banner-content Onecad_clearfix">
<div class="slogan-text por fl">
<p><?php echo get_bloginfo('name'); ?><i class="iblock poa corner" style="background:url(//s1si.com/wp-content/themes/zibll/img/hot.svg) no-repeat;"></i></p>
<p class="promote-sub-title line-one">已发布<span style="display: inline-block;overflow: hidden;line-height: 34px;vertical-align: -9px;">
<em id="goal-works" value="5351266" style="font-style: normal;">
<ps style="color: #26d6c8;"><?php $count_posts = wp_count_posts(); echo $published_posts =$count_posts->publish;?></ps>
</em>
</span>篇文章内容</p>
</div>
</div>
<div class="home-banner-search por searchv2-top-m">
<div class="primary-menus" style=" position: unset;transform: translate(1px, 1px);">
<div class="cont">
<div class="left-cont">
<form class="search" id="search_4" action="/?s=" method="get" target="_blank">
<input type="text" name="s" class="s" placeholder="输入关键词 按回车搜索">
<button type="submit" name="" class="btn">
站内搜索
</button>
</form>
<div class="tag"><a href="/?s=源码" target="_blank">源码</a><a href="/?s=模板 " target="_blank">模板</a><a href="/?s=插件" target="_blank">插件</a><a href="/?s=软件" target="_blank">软件</a></div>
</div>
</div>
</div>
</div>
</div>
<!-- 头部快速链接导航 -->
</div>
</div>
<div id="home-row-qukuai" class=" home_row home_row_1 module-qukuai " style="background-color:;">
<div class="wrapper">
<div class="home-row-left content-area ">
<div class="sort jitheme_radius" style="margin-top:-80px ;">
<ul class="sort-config">
<li>
<div class="sort-config-item">
<img class="sort-config-icon" src="//www.ytshopcn.com/img/提示.svg" >
<a href="https://s1si.com/forums" target="_blank"><p class="sort-config-title">社区
</p> </a>
<span class="sort-config-desc">S14社区论坛</span>
</div></li> <li>
<div class="sort-config-item">
<img class="sort-config-icon" src="//www.ytshopcn.com/img/文章.svg" >
<a href="https://s1si.com/forum/146.html" target="_blank"><p class="sort-config-title">消息
</p> </a>
<span class="sort-config-desc">网站最新消息</span>
</div></li> <li>
<div class="sort-config-item">
<img class="sort-config-icon" src="//www.ytshopcn.com/img/图片.svg" >
<a href="https://s1si.com/forum/263.html" target="_blank"><p class="sort-config-title">建议
</p> </a>
<span class="sort-config-desc">网站文章需求建议</span>
</div></li> <li>
<div class="sort-config-item">
<img class="sort-config-icon" src="//www.ytshopcn.com/img/安全.svg" >
<a href="https://s1si.com/user/vip" target="_blank"><p class="sort-config-title">会员
</p> </a>
<span class="sort-config-desc">开通会员页面</span>
</div></li> <li>
<div class="sort-config-item">
<img class="sort-config-icon" src="//www.ytshopcn.com/img/注意.svg" >
<a href="https://s1si.com/user/" target="_blank"><p class="sort-config-title">用户中心
</p> </a>
<span class="sort-config-desc">用户中心页面</span>
</div></li> </ul>
</div>
</div>
</div>
</div>
<style scoped>
#page-wrapper {
padding-bottom:16px;
margin-top:-16px;
}
.left-cont a, .sort-config span,.wrapper p,.sort jitheme_radius ul,.sort jitheme_radius li {
border: 0;
font-family: inherit;
/*font-size: 100%;*/
font-style: inherit;
font-weight: inherit;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
word-wrap: break-word;
box-sizing: border-box;
}
.por {
position: relative;
}
.home-banner {
position: relative;
/* z-index: 1; */
background-position: 0 100%;
animation: gradient 12s ease-in-out infinite;
}
.home-banner .section {
position: relative;
width: 100%;
overflow: hidden;
/* max-height: 600px; */
/* height: calc(100vh - 220px); */
}
.home-banner .section .video-wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
position: absolute;
overflow: hidden;
z-index: 0;
}
.home-banner .section .video-wrapper video {
visibility: visible;
pointer-events: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
height: 100%;
width: 100%;
object-fit: cover;
}
canvas, img, video {
max-width: 100%;
height: auto;
box-sizing: border-box;
}
audio, canvas, iframe, img, svg, video {
vertical-align: middle;
}
.home-banner .section .video-overlay {
height: 100%;
width: 100%;
top: 0;
left: 0;
position: absolute;
background: rgba(45,47,54,.15);
}
.poa {
color: #fff;
}
.slogan-text.por.fl {
/* margin-left: 200px; */
text-align: center;
width: 100%;
margin-bottom: 50px;
}
.fl {
float: left;
}
.por {
position: relative;
}
.home-banner-content .slogan-text p:nth-of-type(1) {
font-weight: 600;
font-size: 28px;
line-height: 46px;
letter-spacing: 6px;
text-shadow: 0 2px 4px rgb(0 0 0 / 25%);
margin-bottom: 20px;
}
.home-banner .corner {
width: 28px;
height: 21px;
position: absolute;
border-radius: 4px;
margin: 0px;
/* left: 340px; */
/* top: 10px; */
}
.home-banner-content .slogan-text p {
font-size: 18px;
line-height: 24px;
letter-spacing: 2px;
font-weight: 600;
text-shadow: 0 2px 4px rgb(0 0 0 / 25%);
}
.Onecad_clearfix:after {
content: '';
clear: both;
display: block;
height: 0;
visibility: hidden;
font-size: 0;
line-height: 0;
}
.home_row {
position: relative;
margin-bottom: 24px /* border-bottom:1px dashed rgba(255, 255, 255, 0.3); */;
}
.home_row > div {
display: flex;
margin: 0 auto;
max-width: 100%;
position: relative;
margin-top: 16px;
}
.wrapper {
/*width: 1300px;*/
width: 1170px;
}
.poa {
position: absolute;
width: calc(100% - 200px);
margin: 0 100px;
}
.home-row-left.content-area {
max-width: 100%;
}
.b2-content .content-area, .post-style-2 .content-area, .archive .content-area {
margin: 0 auto;
}
.content-area {
width: 100%;
max-width: 100%;
}
.sort, .jitheme_slide_jb, .jitheme_radius {
border-radius: 10px;
}
.sort {
position: relative;
z-index: 3;
padding: 26px;
background: rgba(255,255,255,0.1);
/* border: 1px solid #797c80; */
/* -webkit-box-shadow: 0 40px 75px 0 rgb(57 60 67 / 8%); */
/* box-shadow: 0 40px 75px 0 rgb(57 60 67 / 8%); */
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
}
.sort-config {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.jitheme-pages-vip ol, ul, li {
list-style: none;
}
.sort-config>li {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
overflow: hidden;
height: 100%;
}
.sort-config-item {
display: block;
height: 100%;
}
.sort-config-item img {
float: left;
width: 62px;
height: 62px;
margin-right: 12px;
}
a, a:active, a:visited {
text-decoration: none;
transition: all .2s;
}
.sort-config-title {
line-height: 34px;
font-size: 18px;
font-weight: 600;
color: var(--main-color);
-webkit-transition: .3s;
transition: .3s;
}
.sort-config-desc {
float: left;
line-height: 22px;
font-size: 14px;
color: #8e8e8e;
}
.hidden {
display: none !important;
}
.home-banner-search {
width: 50%;
/* margin-left: 209px; */
height: auto;
margin: auto;
}
.left-cont {
border: 5px solid rgb(255 255 255 / 18%);
border-radius: 30px;
}
.home-banner-search form>input {
width: 100%;
height: 50px;
background: #fff;
border: none;
padding: 18px 22px;
font-size: 14px;
color: #333;
border-radius: 30px;
}
.home-banner-search input, textarea {
border-radius: 0px;
}
button, input[class="s"] {
-webkit-appearance: none;
outline: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
font-family: -apple-system,BlinkMacSystemFont,Helvetica Neue,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;
border: 1px solid #ccc;
box-sizing: border-box;
}
.primary-menus .left-cont button {
height: 50px;
box-sizing: border-box;
min-width: 100px;
/* margin-left: 0px; */
cursor: pointer;
color: #fff;
font-size: 15px;
line-height: 40px;
position: absolute;
right: 5px;
top: 5px;
border-radius: 1px 30px 30px 1px;
padding: 0 15px;
transform: translateY(0px);
}
.button, button {
background: #fc3c2d;
border: 1px solid #fc3c2d;
border-radius: 0px;
}
.home-banner-search .tag {
position: absolute;
right: 100px;
top: 0;
padding: 15px 10px;
display: none;
}
.home-banner-search .tag a {
display: inline;
padding: 0px 8px;
border-radius: 10px;
background: #EFEFEF;
float: left;
margin: 5px;
height: 20px;
line-height: 20px;
color: #A0A0A0;
font-size: 12px;
}
.home-banner-search .tag a:hover {
background: #fc3c2d;
color: #fff;
}
@media (max-width:776px) {#page-wrapper {display: none;}
#home-row-qukuai {display: none;}
}
@media (min-width: 1440px){
.home-banner-search .tag{display:block}
}
</style>
<?php
}
}[/acc]
此搜索框只能在pc端查看
只能用视频文件替代背景
视频背景高度在代码11行修改
视频链接地址在代码13行修改
其他的自己研究研究吧,教程结束。
先去网站下载一些你喜欢的字体。
这里给大家列举一些个人觉得比较好的下载站。
100字体下载站
猫啃网
下载后,会得到一个.ttf的文件(压缩包的解压)。
但是经过测试,.ttf的字体在部分浏览器不能生效(如Safari)
所以,需要转换成eot,woff,woff2,svg其中一个就好。推荐.woff
字体转换 (转换教程不多讲)
把文件上传至网站根目录(可以是其他地方,不推荐)只需要记住地址就行。
例子:https://www.wabm.cn/font.tff
font.tff是字体文件名,实际使用时需更改(包括网站链接)
以下代码添加到zibll主题>自定义代码>自定义CSS里。
@font-face{
font-family: 'moe';
src: url('https://blog.gtwxxh.cc/font.ttf');
src: url('https://blog.gtwxxh.cc/font.woff');
}
body{
font-family:'moe';
}
.enlighter-default .enlighter{max-height:400px;overflow-y:auto !important;}.lazyloading:not(.swiper-lazy-loaded){opacity: 0;}@media (max-width:640px) {
.meta-right .meta-view{
display: unset !important;
}
}font-family 是自定义字体名称(自己修改),url 这是字体文件的地址(自己修改)
如果要添加多个字体文件,你有可能需要注意代码规范。