【发布时间】:2017-04-29 18:18:45
【问题描述】:
我在我的网站 gintlemen.com 上使用 Algolia,我不希望通过 Yoast SEO 插件设置为 noindex 的帖子被 Algolia 索引。
我找到了这篇文章https://community.algolia.com/wordpress/indexing-flow.html,但我不确定将 sn-p 放在哪里。
你能帮我解决这个问题吗?
【问题讨论】:
我在我的网站 gintlemen.com 上使用 Algolia,我不希望通过 Yoast SEO 插件设置为 noindex 的帖子被 Algolia 索引。
我找到了这篇文章https://community.algolia.com/wordpress/indexing-flow.html,但我不确定将 sn-p 放在哪里。
你能帮我解决这个问题吗?
【问题讨论】:
要排除 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 );
【讨论】: