level 8
祥哥依然_潇洒
楼主
我用wordpress程序 用了外链转内链代码 如下 。 当我的文章中出现淘宝链接是自动跳转成淘客链接
首先,在你当前使用的主题的 functions.php 中加入以下代码
// 自动给文章的外部链接添加nofollow属性
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
preg_match_all('/href="(http.*?)"/',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false )
$content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/link?url=" .base64_encode($val). "\"",$content);
}
}
return $content;
}
然后在网站根目录下新建个 link 的文件夹,在其中写个 index.php 的文件,内容如下(请保存为UTF-8):
<?php
$url = $_GET['url'];
$a = '';
if( $a==$url ) {
$b = "http://www.qweiw.com/";
// echo 'true';
} else {
$b = $url;
$b = base64_decode($b);
}
//Template Name:链接跳转(有过度)
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0.1;url=<?php echo $b; ?>">
<title>正在跳转....</title>
</head>
<body>
</body>
</html>
2015年09月05日 08点09分
1
首先,在你当前使用的主题的 functions.php 中加入以下代码
// 自动给文章的外部链接添加nofollow属性
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
preg_match_all('/href="(http.*?)"/',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false )
$content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/link?url=" .base64_encode($val). "\"",$content);
}
}
return $content;
}
然后在网站根目录下新建个 link 的文件夹,在其中写个 index.php 的文件,内容如下(请保存为UTF-8):
<?php
$url = $_GET['url'];
$a = '';
if( $a==$url ) {
$b = "http://www.qweiw.com/";
// echo 'true';
} else {
$b = $url;
$b = base64_decode($b);
}
//Template Name:链接跳转(有过度)
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0.1;url=<?php echo $b; ?>">
<title>正在跳转....</title>
</head>
<body>
</body>
</html>