Title: Cannot successfully prevent certain content from indexing
Last modified: November 14, 2024

---

# Cannot successfully prevent certain content from indexing

 *  [korynorthrop](https://wordpress.org/support/users/korynorthrop/)
 * (@korynorthrop)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcannot-successfully-prevent-certain-content-from-indexing%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18135308)
 * Have you tried debugging these functions to see why they are not working?
 * In the first one, check what values `$block['blockName']` gets when you save 
   the post. Is the name correct? Usually Gutenberg block names are prefixed with
   something, so perhaps there’s a prefix you’re missing.
 *  Thread Starter [korynorthrop](https://wordpress.org/support/users/korynorthrop/)
 * (@korynorthrop)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18135350)
 * [@msaari](https://wordpress.org/support/users/msaari/) thanks for the quick reply,
   I already did that to ensure that the blocks were properly detected (I logged
   the name of the block to the PHP error log in those Relevanssi hooks). The names
   are correct (I shortened them in this support ticket for brevity’s sake, but 
   an example of the full block name is “acf/rcp-faqs” and that is what gets printed
   in the error_log when I checked that I had the right names).
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18135428)
 * So the function triggers and returns `null` for the blocks? If you check with`
   relevanssi_post_content` on a priority higher than 10 (see [https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_post_content/](https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_post_content/)),
   is the rendered block output included or not?
 * If you check with the Relevanssi debugger, do the functions have any effect on
   the Relevanssi indexing?
 *  Thread Starter [korynorthrop](https://wordpress.org/support/users/korynorthrop/)
 * (@korynorthrop)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18136603)
 * Yes, the **relevanssi_block_to_render** function is returning `null` for the 
   desired blocks, which I verified by PHP error_log messages (e.g. right before
   the `return null;` I have this `error_log( 'Relevanssi: Returning null for block:'.
   $block['blockName'] );` and I see this printed out in the PHP log quite a bit
   as expected).
 * Using the **relevanssi_post_content** hook with a priority of 20, I am outputting
   the `$post_content` of one of the posts that _shouldn’t_ be indexed because the
   only place the search term shows up is in one of the custom blocks that is supposedly
   returned null by the previous hook. However, when I look at the $post_content
   that is printed to the error log, I still see the unwanted blocks and the search
   term content inside those block’s markup.
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18137145)
 * That’s curious. I don’t know what’s going on here and where the block content
   comes in. What you’re doing should be enough.
 * What if you delete to block content in the `relevanssi_post_content` function?
   Does that get you rid of it for good?
 *  Thread Starter [korynorthrop](https://wordpress.org/support/users/korynorthrop/)
 * (@korynorthrop)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18140386)
 * I was able to get rid of one of these undesired posts from the search results
   by returning an empty string for it’s $post_content in the `relevanssi_post_content`
   filter. So, _something_ is working, now to figure out why I’m not able to get
   the other filters to work properly….Do you have any other ideas of how to troubleshoot
   this?
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18142969)
 * Well, you could always investigate what happens in the `relevanssi_gutenberg_block_rendering()`
   function (it’s in /lib/compatibility/gutenberg.php) to see how the block is handled
   and what the function returns. If the function returns an empty string as it 
   should, then the next step is to figure out where the block content is coming
   from if not there. Is it possible the content is also somewhere else?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Cannot successfully prevent certain content from indexing’ is closed 
to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=2025044)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/cannot-successfully-prevent-certain-content-from-indexing/#post-18142969)
 * Status: not resolved