Posted on

Disabling title or content indexing

If you want to prevent the indexing titles or post content for some reason, Premium has couple of useful filters starting from version 1.5.5.

The filters are called relevanssi_index_content and relevanssi_index_titles. These are simple true/false filters, so if you want to activate the filter, add a function that returns false, like this:

add_filter('relevanssi_index_content', 'contentoff');
function contentoff() {
    return false;
}

That’s all. Replace relevanssi_index_content with relevanssi_index_titles to stop titles (and please don’t stop both at the same time).

Once you’ve got the function in your functions.php file, you need to reindex the database. If you’ve stopped post content, indexing should be much faster than usual.

If you then remove the function, the effect will remain until you reindex the database (or posts are indexed when they are updated).

45 comments Disabling title or content indexing

    1. Do i have to upgrade to Relvanssi premium to be able to exclude post titles from my search results? Or can I just set the weight to 0?

  1. I want to search only in Post Titles, how can i do so? I’ve set the weight 10 to Post titles and 0 to everything else + i added the filter above for content.

    With all this it still searches in content/excerpt although “Create custom search result snippets” is disabled.

    I get search results which have no searched word in title but it has in content above search results that have the search keywords in title.

    Solution?

    Thanks.

  2. If you add the filter, nothing from post content will go to the index. If you have the filter in place, correctly set up, and have indexed the database after that, and you still get hits from post content, your theme is probably stopping Relevanssi from working at all and you’re getting WordPress search results.

        1. No, that’s not the same. You need to modify your search results template. I don’t know what your search results template is currently showing, so it depends on that, but Relevanssi-generated excerpts should not have images in them.

          1. Mikko, thanks for the info! i’ve just installed and activated Relevanssi, but my search results simply contain a list of each of the pages that match the result. I’ve indexed a couple times so far. How can I get it to show the special snippets and remove images? I found an option for limiting the size of a snippet, but that didn’t work. Is there a different widget I should use, or just the main one? http://www.nationalloopcompany.com Thanks! I just wanna use Relevanssi! 🙂

          2. Yu need to adjust your search results template. The look of the results depends from your theme, Relevanssi doesn’t actually have anything to do with it.

          3. Thanks for the reply! So just to clarify, (because believe it or not this info isn’t in the user guide) we just have to install, activate, build db, and use the standard WordPress widget? Thanks!

          4. is it under the “Basic use and parameters” section? that link isn’t clickable.
            I’ve searched this website and the wordpress.org site, but neither seem to have directions that say anything about using the widget. If you do a search for “Widget” you’ll see what i mean. One would think that the directions would have to say “widget” at least once. The directions say nothing about using the widget. Thanks!

          5. Thanks for the update! It’s very understandable to feel that way. Obviously, we wouldn’t have had this conversation if you were correct. You can simply write something to the effect of “1. Install, 2. Activate, 3. Build DB, 4. and use the standard widget included with wordpress.” BOOM problem solved. There are a lot of threads out there with people asking the same question as me. I wish you the best of success! one hint… try to assume your users are idiots like me, we neeeeeed detailed instructions or else we waste your time with crap like this 🙂 Best Regards!

  3. There is a way to exclude some blocks of text (in a post or page) from
    be indexing and therefore displayed in the search results of Relevanssi?

      1. Could I have a more detailed explanation of how to use this “noindex” shortcode? Does it work in the free version?

  4. I added the above code (but with relevanssi_index_titles) to my functions.php file, the post titles still appear in the search results. Do I need to have the Premium version to get this to work?

      1. I added this code to my functions.php file

        add_filter(‘relevanssi_index_titles’, ‘contentoff’);
        function contentoff() {
        return false;
        }

        then I went to Relevannsi to Build the Index. After doing a search I still see post titles within the excerpts. Are we missing some setting or is there another way to prevent post titles from appearing in the search results?

      1. I really would like to use this plugin but I need to exclude the post content. Is there any simple way for a newbie to do this?
        hidemyage.com

          1. Thank you Mikko! You’ve taught me something new! Much appreciated.

            A couple of questions…

            How can I include featured image thumbnails in my search results?

            Can you take a look at my site and tell me if I would benefit from upgrading to the premium version? I don’t have a lot of information on there yet…

            Thanks!!
            Kim
            hidemyage.com

          2. Kim, to add image thumbnails, you need to edit your search results template.

            Upgrading to Premium is a great idea, if you need to get user profiles or taxonomy terms in the search results. If you don’t, then the benefits are smaller.

  5. Why I have to disable the filter relevanssi_index_content if I do not want to. The problem is that when indexing the content, code try to execute shortcodes (in the content), so, whene executed, template functions are not load, so -> FATAL ERROR.

    I would like a nice solution for this issue.

    Line: lib/indexing.php: 367

    (for example, woocommerce shortcode are going to cause a Fatal Error).

    1. You certainly don’t need to disable content indexing unless you don’t want to. See Relevanssi settings: there’s an option to disable shortcode expansion in indexing. Uncheck that option and WooCommerce shortcodes won’t cause problems anymore.

  6. Would this also work in the backend – specifically, in WooCommerce – when creating a new order manually when I add a product I want to stop the search looking in the product description – just the title.

    Thanks

      1. Thanks – I’ve added it to my functions.php and it works for the product searches on the front end and in the All Products list in the backend.

        But, when I manually add an order and select Add Items -> Add Product the searching in there still uses the product description – is there any way to make this bit ignore the description too?

        Thanks

        1. I’m not very familiar with WooCommerce, but I’m guessing that search is not actually powered by Relevanssi in the first place, and likely won’t be possible to handle with Relevanssi.

  7. since wordpress 3.0 there is this funky build in return false function:
    add_filter(‘relevanssi_index_content’, ‘__return_false’);

    how would i implement this on a post-type basis..? something like: please index post content, but ignore page content..?

    1. and no, its not that i want to exclude pages from indexing, this is just an example.. i would need a function to remove post content from being indexed, but only for a specific post type..

      1. This is a really blunt instrument, with no adjustment. But you can use “relevanssi_post_content”. It gets two parameters: post content and post object. Check the post object and if conditions match, return an empty string. That does the trick.

Leave a Reply

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