apply_filters( 'relevanssi_post_content', string $post_content, object $post_object )
Filters the post content before Relevanssi indexes the post.
Parameters
$post_content
(string) The post content from $post->post_content
as a string.
$post_object
(object) The whole post object. Always similar to a WP_Post object, but not always exactly that class.
More information
The post indexing process. When Relevanssi indexes the post content, first Relevanssi checks the relevanssi_index_content
filter hook to see if that’s allowed. If it is, the noindex
shortcode is activated and then the post content is passed through this filter hook.
After that, the content from the relevanssi_content_to_index
filter hook is added to the post content. Then the shortcodes are expanded if necessary, and the content is passed through the relevanssi_post_content_after_shortcodes
filter hook. Then tags are stripped, and the finally the content is passed through the relevanssi_post_content_before_tokenize
filter hook.
Then the content is split into tokens (individual words), which are filtered with relevanssi_indexing_tokens
.
Which hook to use? So, this filter hook is the first of many hooks that let you modify the post content as it’s being indexed. In general, if you’re looking to modify the original post content somehow, for example to remove something or alter something, this filter hook is a good place to do that.
If you’re just adding new content, you can do it here, but it may be more logical to do it in relevanssi_content_to_index
. If you want to modify content that is coming from shortcodes (for example content generated from page builder shortcodes), relevanssi_post_content_after_shortcodes
is a good spot.
Don’t forget the excerpts. In many cases, you want to apply the same filters to relevanssi_excerpt_content
to make the modifications available for excerpts as well. However, remember that while this hook only fires when the post is indexed, ie. not often, relevanssi_excerpt_content
filter runs once per post every time you search. You can do time-consuming things in relevanssi_post_content
, but shouldn’t do anything slow in relevanssi_excerpt_content
.
Default functions
relevanssi_remove_page_builder_shortcodes
(priority 9) removes unwanted page builder shortcodes (seerelevanssi_page_builder_shortcodes
).relevanssi_index_ninja_tables
(priority 10) replaces the Ninja Tables table shortcodes with the table contents.relevanssi_gutenberg_block_rendering
(priority 10) renders Gutenberg blocks.