Cannot successfully prevent certain content from indexing
-
I have been looking through the Relevanssi documentation and previous support tickets to figure out this issue, but all of my attempts have been unsuccessful. I am trying to ignore content that is found in specific custom Gutenberg blocks from being indexed by Relevanssi because our search results are being populated with posts that are irrelevant and only appear because they include the searched term in a few specific blocks that aren’t really part of the post’s pertinent content.
First I tried using the relevanssi_block_to_render hook to return null if the block is one of the ones we want to ignore:function relevanssi_no_index_blocks( $block ) {
$blocks_to_ignore = array( 'rcp-accordion', 'rcp-faqs', 'rcp-testimonials' );
if ( in_array( $block['blockName'], $blocks_to_ignore ) ) {
return null;
}
return $block;
}
Then I tried using the relevanssi_rendered_block hook to change the content of those same blocks to be an empty string before Relevanssi finishes indexing the content:function relevanssi_empty_out_block_content( $content, $block ) {
$blocks_to_ignore = array( 'rcp-accordion', 'rcp-faqs', 'rcp-testimonials' );
if ( in_array( $block['blockName'], $blocks_to_ignore ) ) {
$content = '';
}
return $content;
}
I also updated the markup of these blocks to add a “relevanssi_noindex” class to the block output and I manually added that class to the blocks in the Gutenberg editor.
None of these measures fixed the issue. I cleared cache and rebuilt the Relevanssi index each time I tried one of these approaches. What am I doing wrong? How can I accomplish what I’m trying to do here? I still want these posts to be indexed, I just don’t want the text/terms inside of these specific blocks to be indexed with the post because I don’t want posts to be displayed in search results if the only place in the post the search term is found is within these three blocks. Thanks for your help!
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.