Continue reading Adding a search form in the navigation menu

Adding a search form in the navigation menu

…the SearchWP Modal Search Form. As the name says, the plugin is from the SearchWP developer Jon Christopher, but it also works great with Relevanssi. This plugin can easily add a search feature to your navigation menu or a site header. The search form also works great on mobile devices….…header. That’s a good reference if you want to build a nice search form in the header. If your theme does not include a built-in search form and you’re not interested in building one yourself, one of the best plugin options is the SearchWP Modal Search Form. As the name…WordPress doesn’t make adding a search form in the navigation menu easy. It’s a popular request, though, and having access to the search in the site header is typical. Relevanssi itself doesn’t have opinions on the user interface. Some themes, like Twenty Twenty, include a built-in search feature in the…

Read more Adding a search form in the navigation menu 0 Comment on Adding a search form in the navigation menu
Continue reading Using Relevanssi in wp_link_query

Using Relevanssi in wp_link_query

If you want to use Relevanssi in the link queries (the search you get when adding links to posts in Classic editor), that’s easy. Make sure Relevanssi is enabled in admin searches, and then add this function: This function will make the Classic Editor link queries use Relevanssi. This approach generally works fine, but if…

Read more Using Relevanssi in wp_link_query 0 Comment on Using Relevanssi in wp_link_query
Continue reading CodeMirror Blocks

CodeMirror Blocks

…attribute. Add this to your theme functions.php: add_filter( ‘the_content’, ‘rlv_restore_codemirror_settings’, 12 ); function rlv_restore_codemirror_settings( $content ) { $data_settings_found = preg_match_all( ‘/data-setting=”{(.*)}”/’, $content, $data_settings ); if ( $data_settings_found ) { foreach ( $data_settings[1] as $data_setting ) { $content = str_replace( $data_setting, htmlentities( $data_setting ), $content ); } } return $content; }……happens outside the block. This problem happens because CodeMirrors stores the block parameters in a settings attribute, and Relevanssi in-document highlighting breaks that attribute. Fortunately, this is easy to fix with a filter function that runs after the Relevanssi in-document highlighting and fixes the broken attribute. Add this to your…

Read more CodeMirror Blocks 0 Comment on CodeMirror Blocks
Continue reading ACF: Field names appearing in excerpts

ACF: Field names appearing in excerpts

…with a filter function: add_filter( ‘relevanssi_index_custom_fields’, ‘rlv_remove_unwanted’ ); function rlv_remove_unwanted( $fields ) { $unwanted_fields[] = ‘flexible_content’; return array_diff( $fields, $unwanted_fields ); } Add this function to your site and rebuild the index. Now the root field is no longer indexed or used in excerpts. Another approach is to stop using……and rebuild the index. Now the root field is no longer indexed or used in excerpts. Another approach is to stop using “Visible” in the custom field indexing settings and instead specify the exact fields you want Relevanssi to index. Still, with lots of Flexible Content, that can be complicated….With Advanced Custom Fields, sometimes Relevanssi picks up custom field names to include in the excerpts. This problem happens when you set Relevanssi to index all visible custom fields and have Flexible Content fields. Let’s assume there’s a Flexible Content field with the name flexible_content. It has a layout named…

Read more ACF: Field names appearing in excerpts 4 Comments on ACF: Field names appearing in excerpts
Continue reading Gutenberg Full Site Editing

Gutenberg Full Site Editing

…core WP excerpt block does not allow Relevanssi highlights in excerpts. It will display Relevanssi excerpts (restricted to the excerpt length in the block settings – make sure the setting in the block is higher than the Relevanssi excerpt length setting), but no highlights will be visible because all the…excerpts are passed through wp_trim_words() which removes HTML tags. This function can be used to overcome this limitation: add_filter( ‘wp_trim_words’, function( $text, $num_words, $more, $original_text ) { global $post; if ( isset( $post->relevance_score ) ) { return $post->post_excerpt; } return $text; }, 10, 4 ); If the post has the……relevance_score attribute set – which should only happen within a search context – this function will cause the wp_trim_words() to return the original post excerpt. With Max Mega Menu, the function above will add the excerpts to the menu items. You can avoid that: add_filter( ‘wp_trim_words’, function( $text, $num_words, $more,…

Read more Gutenberg Full Site Editing 2 Comments on Gutenberg Full Site Editing
Continue reading Oxygen and Ninja Tables

Oxygen and Ninja Tables

Relevanssi has support both for Oxygen and Ninja Tables, but the way the Ninja Tables support is done, it’s not working when used with Oxygen. The Ninja Tables support in Relevanssi is looking for the Ninja Tables shortcodes in the post content, but Oxygen keeps everything in custom fields. Fortunately, the fix is simple: you…

Read more Oxygen and Ninja Tables 0 Comment on Oxygen and Ninja Tables
Continue reading ACF: Indexing File field title

ACF: Indexing File field title

I use the ACF field type File for a download section, but the displayed file title is not indexing. The format I return the ACF field data is “File Array (array)”. For Relevanssi, it doesn’t matter which ACF return format you choose. Relevanssi doesn’t use get_field() but instead uses the…

Read more ACF: Indexing File field title 0 Comment on ACF: Indexing File field title
Continue reading Click tracking

Click tracking

…element. The results are cached for a week to avoid excessive database calls. Permalink Manager Pro The Permalink Manager Pro plugin removes the Relevanssi click tracking parameters from the permalinks. Here’s how you can restore the tracking parameters: add_filter( ‘permalink_manager_filter_final_post_permalink’, ‘pm_relevanssi_add_tracking’, 999, 3 ); function pm_relevanssi_add_tracking( $permalink, $post, $old_permalink )……{ global $relevanssi_tracking_permalink; if ( ! function_exists( ‘relevanssi_add_tracking’ ) ) { return $permalink; } if ( isset( $relevanssi_tracking_permalink[ $post->ID ] ) ) { unset( $relevanssi_tracking_permalink[ $post->ID ] ); } $permalink = relevanssi_add_tracking( $permalink, $post ); return $permalink; } Problems with permalinks Sometimes, click tracking may cause problems with permalinks. If……click tracking may cause problems with permalinks. If you notice broken permalinks on search results pages and disabling the click tracking fixes the problem, you can disable the click tracking permalink cache with this snippet. add_filter( ‘relevanssi_add_highlight_and_tracking’, function( $value ) { global $relevanssi_tracking_permalink; $relevanssi_tracking_permalink = array(); return $value; } );…

Read more Click tracking 0 Comment on Click tracking