【问题标题】:How to stop Algolia from indexing posts with noindex in Wordpress如何阻止 Algolia 在 Wordpress 中使用 noindex 索引帖子
【发布时间】:2017-04-29 18:18:45
【问题描述】:

我在我的网站 gintlemen.com 上使用 Algolia,我不希望通过 Yoast SEO 插件设置为 noindex 的帖子被 Algolia 索引。

我找到了这篇文章https://community.algolia.com/wordpress/indexing-flow.html,但我不确定将 sn-p 放在哪里。

你能帮我解决这个问题吗?

【问题讨论】:

    标签: wordpress algolia


    【解决方案1】:

    要排除 Yoast 标记为“noindex”的帖子,您需要将以下 sn-p 添加到活动主题的 functions.php

    <?php
    /**
     * Don't index pages where the robot index option
     * in the Yoast SEO plugin is set to noindex.
     *
     * @param bool    $should_index
     * @param WP_Post $post
     *
     * @return bool
     */
    function filter_post( $should_index, WP_Post $post )
    {
        if ( false === $should_index ) {
            return false;
        }
    
        return get_post_meta($post->ID, '_yoast_wpseo_meta-robots-noindex', true) == 1 ? false : true;
    }
    
    // Hook into Algolia to manipulate the post that should be indexed.
    add_filter( 'algolia_should_index_searchable_post', 'filter_post', 10, 2 );
    add_filter( 'algolia_should_index_post', 'filter_post', 10, 2 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 2014-05-17
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      相关资源
      最近更新 更多