Posted on

Index only short numbers

Relevanssi has a minimum word length setting that is set to three characters. Any one- or two-letter words are not indexed unless you change this setting from the Relevanssi advanced indexing settings. Sometimes it would be helpful to ignore short words but to index one- and two-digit numbers.

You can do that with a bit of help. Adjust the minimum word length to 1 or 2 depending on your needs, add this function to your site and rebuild the index:

add_filter( 'relevanssi_remove_punctuation', function( $str) {
    return implode(
        ' ',
            explode( ' ', $str ),
            function( $word ) {
                if ( relevanssi_strlen( $word ) < 3 ) {
                    return is_numeric( $word );
                return true;
} );

This function will let short numbers through while blocking short words.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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