【问题标题】:Cannot remove action noindex in wordpress无法删除 wordpress 中的操作 noindex
【发布时间】:2015-12-10 07:02:54
【问题描述】:

我已经做了一些研究并使用了这段代码

remove_action('wp_head','noindex',1);

但显然它没有删除我的 WordPress 标头中的 <meta name="robots" content="noindex,follow"/>。我正在使用 WordPress 4.2.3

【问题讨论】:

  • 查看设置中管理部分的搜索引擎可见性>>阅读
  • @yjs 是的,我把它放在functions.php上
  • @ash,我想覆盖 WordPress 默认功能,这就是为什么我试图删除它并添加我自己的一组元机器人
  • 我有一个类似的问题,对我来说,甚至通过管理面板禁用/启用它正在呈现<meta name="robots" content="noindex,follow"/>

标签: wordpress nofollow noindex


【解决方案1】:

? 我在这里找到了适合我的解决方案:? https://wordpress.org/support/topic/disable-noindex-on-certain-core-pages-2/

add_action( 'init', 'remove_wc_page_noindex' );
function remove_wc_page_noindex(){
    remove_action( 'wp_head', 'wc_page_noindex' );
}

这个问题似乎在三个线程上:

  1. How do I stop Wordpress from inserting a noindex meta tag?
  2. Wordpress remove Robots Meta Tag noindex
  3. Cannot remove action noindex in wordpress

【讨论】:

    【解决方案2】:

    使用 WordPress 5.7.0 中引入的 wp_robots 挂钩来过滤其机器人元标记输出。

    示例函数:

    add_filter( 'wp_robots', 'wp_robots_remove_noindex', 999 );
    
    function wp_robots_remove_noindex( $robots ){
      
      //put any conditionals here to target certain pages
      if ( is_search() || is_archive(  ) || is_404(  ) ) {
    
        //set the index and noindex array items
        $robots[ 'index' ] = true;
        $robots[ 'noindex' ] = false;
      }
    
      return $robots;   
    }
    

    这会产生以下输出: <meta name='robots' content='index, follow' />

    【讨论】:

      【解决方案3】:

      登录您的 WordPress 网站。

      登录后,您将在“仪表板”中。

      点击“设置”。在左侧,您将看到一个菜单。 ...

      点击“阅读”。 ...

      取消选中“阻止搜索引擎将此站点编入索引”。

      点击“保存更改”。

      【讨论】:

        【解决方案4】:

        我将向您展示如何使用替换管理面板中的一些代码来删除 WordPress 中的 meta name='robots' content='noindex nofollow'。

        第 1 步 - public_html → wp-includes → general-template.php

        嗯,你登录到public_html目录,现在你找到一个文件夹,名字是wp-includes,双击打开这个文件夹。同时,还有这么多文件夹和文件,喘口气,简单地点击键盘Ctrl+f找到文件并输入general-template.php

        第 2 步 - 编辑两个函数

        - 第一个代码函数查找:

        function wp_no_robots() {
        if ( get_option( 'blog_public' ) ) {
            echo "<meta name='robots' content='noindex,follow' />\n";
            return;
        }
        
        echo "<meta name='robots' content='noindex,nofollow' />\n";
        

        }

        - 第一个代码替换为波纹管

        function wp_no_robots() {
        if ( get_option( 'blog_public' ) ) {
            echo "<meta name='robots' content='index,follow' />\n";
            return;
        }
        echo "<meta name='robots' content='index,follow' />\n";
        

        }

        - 第二代码函数查找:

        function wp_sensitive_page_meta() {
        ?>
        <meta name='robots' content='noindex,noarchive' />
        <meta name='referrer' content='strict-origin-when-cross-origin' />
        <?php
        

        }

        - 第二个代码替换为以下代码:

        function wp_sensitive_page_meta() {
        ?>
        <meta name='robots' content='index,archive' />
        <meta name='referrer' content='strict-origin-when-cross-origin' />
        <?php
        

        }

        I hope that helps, For full Details Click this link:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-03-18
          • 2023-04-06
          • 2022-07-06
          • 1970-01-01
          • 1970-01-01
          • 2022-07-04
          • 1970-01-01
          • 2021-10-04
          相关资源
          最近更新 更多