最新活动:电脑PC端+手机端+微网站+自适应网页多模板选择-建站388元起价!!!
要源码
当前位置:主页 > 网站建设 > WordPress文章外链中转跳转教程,建站技术

WordPress文章外链中转跳转教程,建站技术

时间:2023-07-23 11:07:23 阅读: 文章分类: 网站建设 作者: 网站开发者

导读:建站技术建站技术在你当前使用的主题的 functions.php 中加入以下代码: //给外部链接加上跳转 add_filter('the_content','the_cont搭建网站网站平台搭建。

搭建网站网站平台搭建

在你当前使用的主题的 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\" ",$content);
  •             }
  •         }
  •     }
  •     return $content;
  • }
  • 新增跳转

    根据以前分享的方法,在网站根目录新增一个文件夹,命名为go,并在go文件夹下新增一个index.php,内容如下:

  • <?php
  • $url = $_GET['url'];
  • Header("Location:$url");
  • ?>
  • 新增robots规则

    为了防止搜索引擎抓取这种跳转链接,我们可以在robots.txt里面新增禁止抓取/go的规则:

  • Disallow: /go
  • 替换评论者的链接

  • //评论链接新窗口  
  • function commentauthor($comment_ID = 0) {  
  •     $url    = get_comment_author_url( $comment_ID );  
  •     $author = get_comment_author( $comment_ID );  
  •     if ( empty( $url ) || 'http://' == $url )  
  •     echo $author;  
  •     else  
  •     echo "$author";  
  • }  
  • 在主题织梦模板免费下裁目录下的functions.php查找是否存在修改评论链接为新窗口commentauthor函数,如果存在则如下修改第8行,将$url修改为/go/?url=$url,其实就dede商城模板是在前面新增一个go跳转即可,相同的道理!

  • //评论链接新窗口  
  • function commentauthor($comment_ID = 0) {  

    关键词标签: 建站 教程 跳转

  • 声明: 本文由我的SEOUC技术文章主页发布于:2023-07-23 ,文章WordPress文章外链中转跳转教程,建站技术主要讲述跳转,教程,建站网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_35309.html

    我的IDC 网站建设技术SEOUC.COM
    专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
  • 5000+合作客服
  • 8年从业经验
  • 150+覆盖行业
  • 最新热门源码技术文章