Continue reading Increasing weight for HTML tags

Increasing weight for HTML tags

…content inside those tags multiple times in the post content (as determined by the numbers in the $weightings array). This multiplication will increase the weight of those words in the Relevanssi index because Relevanssi counts how many times each word appears in each document. Thanks to Greg Perham from Swing…Relevanssi ignores HTML tags when indexing posts. If you want to give more weight to words that appear in specific HTML tags (like headings), here is one way to do that. You can add this filter function on your site to the theme functions.php or in a code snippet: add_filter(…‘relevanssi_post_content’, ‘rlv_html_tag_boost’ ); function rlv_html_tag_boost( $content ) { $weightings = array( ‘h1’ => 5, ‘h2’ => 4, ‘h3’ => 2, ‘strong’ => 1, ); foreach ( $weightings as $tag => $weight ) { if ( preg_match_all( “#<$tag.*?>(.*?)</$tag>#”, $content, $elements ) ) { foreach ( $elements[1] as $el_content ) { while…

Read more Increasing weight for HTML tags 0 Comment on Increasing weight for HTML tags
Continue reading Indexing image alt texts

Indexing image alt texts

Relevanssi by default ignores image alt texts (and other tag attributes). That’s often the right thing to do because alt texts aren’t visible to users. Finding a post with a search term that only appears in an alt text may confuse a user. If your alt texts are well crafted, they may help search. It’s…

Read more Indexing image alt texts 0 Comment on Indexing image alt texts
Continue reading Visual Composer: Indexing headings

Visual Composer: Indexing headings

Relevanssi doesn’t by default index the headings in Visual Composer. The vcex_heading shortcode Visual Composer for the headings stores the heading text inside a shortcode attribute. By default, Relevanssi does not index shortcode attributes. In this case, indexing the shortcode attribute is necessary. Fortunately, it’s easy to fix with a…

Read more Visual Composer: Indexing headings 0 Comment on Visual Composer: Indexing headings
Continue reading Visual Composer: Indexing Raw HTML elements

Visual Composer: Indexing Raw HTML elements

Visual Composer and WP Bakery have a Raw HTML element that can be used to add HTML code to your pages. By default, this content is stored in an encoded format Relevanssi can’t read. Fortunately, the encoding is simple Base64 encoding that is easy to read. So, in order to…

Read more Visual Composer: Indexing Raw HTML elements 0 Comment on Visual Composer: Indexing Raw HTML elements
Continue reading Why is a post type excluded from search?

Why is a post type excluded from search?

…even though it has been excluded from the search. Relevanssi can index posts that are excluded from the search. If you have indexed an excluded post type, the column will still say the post type is excluded from the search, because the setting that is defined when the post type……“Respect exclude_from_search” option in the Relevanssi searching settings. As you can see, Relevanssi will suggest you need to uncheck this option if you choose to index an excluded post type. In many cases it’s good to stop and think before you index an excluded post type: there’s a good chance……there’s almost always a good reason why these post types are excluded from the search in the first place. However, sometimes there are situations where it would be useful to include these excluded posts in the search. That’s possible with Relevanssi: all you need to do is to uncheck the…

Read more Why is a post type excluded from search? 0 Comment on Why is a post type excluded from search?
Continue reading Indexing only attributes from shortcodes

Indexing only attributes from shortcodes

…about a Visual Composer shortcode, it’s worth noticing the new filter must happen on priority 8 or earlier, because on priority 9, Relevanssi runs the relevanssi_remove_page_builder_shortcodes() function that removes all Visual Composer shortcodes, including this vc_custom_heading. As long as the new filter runs before the default function, there’s no problem….I need to add some custom shortcodes to the list of the “removed” ones (so they don’t show in plain text in the results). However, some of them are built like [shortcode_name text=”Need to keep this in results”] and I would like the content in the text parameter to stay in the results. How…

Read more Indexing only attributes from shortcodes 0 Comment on Indexing only attributes from shortcodes
Continue reading Indexing product codes with and without spaces

Indexing product codes with and without spaces

A Relevanssi Premium customer had a problem with product codes. The codes are in the format “ABC 100”, a group of letters and digits with a space in between. Users may search for the codes without the space, so the post should be found with “ABC 100” or “ABC100”. The product codes don’t appear in…

Read more Indexing product codes with and without spaces 10 Comments on Indexing product codes with and without spaces
Continue reading Excluding old content from the search

Excluding old content from the search

…* Adds a date filter to the search query. * * @param WP_Query $query The query object. * * @return WP_Query The modified query object. */ function rlv_date_filter( $query ) { $date_query = array( ‘after’ => ‘January 1st, 2016’, ‘inclusive’ => true, ); $query->set( ‘date_query’, $date_query ); return $query; }……$restriction[‘reason’] .= ‘ News post too old’; return $restriction; } If, on the other hand, you only want to apply this filter in searching, you can use the WP_Query date parameters like this: add_filter( ‘relevanssi_modify_wp_query’, ‘rlv_date_filter’ ); /** * Adds a date filter to the search query. * * @param…

Read more Excluding old content from the search 2 Comments on Excluding old content from the search
Continue reading Indexing image captions for the posts

Indexing image captions for the posts

The use case is I run several newspapers, and the “caption” field when uploading media is where the journalists put the photographer credit. We need to be able to index the photographer bylines, but ideally would want to return the story/commentary where their image was used, not the image itself. If you want to index…

Read more Indexing image captions for the posts 0 Comment on Indexing image captions for the posts