Skip to main contentSkip to footer

By default, Relevanssi does not index HTML comments inside your posts. Relevanssi removes all HTML tags before indexing, and HTML comments (<!– like this –>) are counted as HTML tags.

If you have content inside comments that you want to be indexed, you need to modify the punctuation control – which is responsible for removing the comments – so that the comments are not removed.

The solution is simple: add this function to your site and rebuild the index.

add_filter( 'relevanssi_remove_punctuation', 'rlv_keep_comments', 9 );
function rlv_keep_comments( $string ) {
	$string = str_replace( '<!', '', $string );
	return $string;
}

This function attaches itself to the punctuation removal filter hook relevanssi_remove_punctuation and since it has priority 9, it runs before the default punctuation removal which runs on priority 10. This function then simply removes the HTML comment start <!, which causes Relevanssi to not remove the comments.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Index custom field contents
Custom fields (also known as post meta or meta fields) are a major part of WordPress the default search won’t…
Indexing embedded PDFs for the parent post

…post_id FROM $wpdb->postmeta WHERE meta_key = ‘_wp_attached_file’ AND meta_value = %s )”, $pdf_url ) ); $content .= $pdf_content; } return $content; } DearFlip DearFlip uses a shortcode that points to the flipbook post, which has a custom field with the PDF URL: add_filter( ‘relevanssi_content_to_index’, ‘rlv_dearflip_content’, 10, 2 ); function rlv_dearflip_content(…

Ordering search results by date
I’m building a directory and would like the oldest posts to automatically display first in the search results, is this…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed