dsfdsf48652 2017-08-31 09:10
浏览 27
已采纳

如何更新wordpress中的404页元标记

I'm using yoast plugin for seo for the blog wordpress in my site by default plugin assigns below meta tag for 404 page

<meta name="robots" content="noindex,follow"/>

I want to update this meta tag to the below one

<meta name="robots" content="noindex,nofollow"/>

I have gone through yoast plugin documentation But didn't find any solution Can this be done using yoast plugin itself or Is thee any other way?

  • 写回答

2条回答 默认 最新

  • drws65968272 2017-08-31 09:20
    关注

    In header.php file for your WordPress theme you can use the below code which uses the conditional tag , is_404 to check if it is 404 page and prints out the meta tag which you wish for. So use the options from yoast plugin wherever you need and if you want to change it for specific pages then you can use the conditional tags.

    <?php if(is_404()): ?>
    <meta name="robots" content="noindex,nofollow"/>
    <?php endif; ?>
    

    The above solution assumes that Yoast Plugin is not adding any meta tags to header. But if Yoast adds it's own meta tags then you can try the below solution

    Add the code to functions.php file

    add_filter('wpseo_robots', 'yoast_no_home_noindex', 999);
    function yoast_no_home_noindex($string= "") {
        if (is_404()) {
            $string= "noindex,nofollow";
        }
        return $string;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了