如何确保更新wordpress后functions.php自添加代码不变
1、新建记事本命名为“robots.txt”,将代码复制到文本内容里面长传到根目录即可。
User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/
Disallow: /wp-includes/
Disallow: /*/comment-page-*
Disallow: /*?replytocom=*
Disallow: /category/*/page/
Disallow: /tag/*/page/
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /comments/feed
Disallow: /?s=*
Disallow: /*/?s=*\
Disallow: /attachment/
Disallow: /go/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-admin/
Disallow: /wp-content/
Disallow: /wp-includes/
Disallow: /*/comment-page-*
Disallow: /*?replytocom=*
Disallow: /category/*/page/
Disallow: /tag/*/page/
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /comments/feed
Disallow: /?s=*
Disallow: /*/?s=*\
Disallow: /attachment/
Disallow: /go/
Allow: /wp-admin/admin-ajax.php
2、新建“tiaozhuan.php”文件,将以下代码复制到文件里面:
<?php
/*
Plugin Name: 数据跳转插件
Description: 设置网站跳转页面
Author: www.cuikaiyun.cn
*/
//文件里面加入代码就可以和functions文件一样了
?>;
/*
Plugin Name: 数据跳转插件
Description: 设置网站跳转页面
Author: www.cuikaiyun.cn
*/
//文件里面加入代码就可以和functions文件一样了
?>;
3、然后从“functions.php”找到之前添加的代码:
//给外部链接加上跳转
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href="$val"", "href="".home_url()."/go/?url=$val" target='_blank'",$content);
}
}
}
return $content;
}
//给外部链接加上跳转-结束
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href="$val"", "href="".home_url()."/go/?url=$val" target='_blank'",$content);
}
}
}
return $content;
}
//给外部链接加上跳转-结束
4、将以上步骤2的代码添加到新建的“tiaozhuan.php”文件“//文件里面加入代码就可以和functions文件一样了”后面,完整如下:
<?php
/*
Plugin Name: 数据跳转插件
Description: 设置网站跳转页面
Author: www.cuikaiyun.cn
*/
//文件里面加入代码就可以和functions文件一样了
//给外部链接加上跳转
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href="$val"", "href="".home_url()."/go/?url=$val" target='_blank'",$content);
}
}
}
return $content;
}
//给外部链接加上跳转-结束
?>;
/*
Plugin Name: 数据跳转插件
Description: 设置网站跳转页面
Author: www.cuikaiyun.cn
*/
//文件里面加入代码就可以和functions文件一样了
//给外部链接加上跳转
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href="$val"", "href="".home_url()."/go/?url=$val" target='_blank'",$content);
}
}
}
return $content;
}
//给外部链接加上跳转-结束
?>;
5、将“tiaozhuan.php”文件上传至“/wp-content/plugins/”目录(不用新建文件夹),上传后打开后台-启用插件。
通过以上方法,以后就不必再担心更新了代码消失的问题了。
本博客 [ 秋硕笔记 ] 内带有 原创 标签文章,均为秋硕独立创作。
撰文不易,转载请注明文章来源并保留原文链接:本文转载自 秋硕笔记。
本文链接:https://www.cuikaiyun.cn/wordpress-updata-functions.html