Posted on

Disabling title or content indexing

If you want to prevent the indexing titles or post content for some reason, Relevanssi has couple of useful filters for that. 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', '__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).

62 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.



  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? 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 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. That code doesn’t affect search results pages. If you don’t want titles on your search results pages, you need to remove them from your search results template.

      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?

          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…


          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.


      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?


        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.

  8. Mikko,
    I want to let my shoppers choose which fields they want to include in search. For example:search only titles, or titles & content, or titles & a custom field like year or location. Is there a way to do that? I’m using Relevanssi Pro.

  9. Hi Mikko,
    If i use this function to not index the content, will it still index excerpts?

    I want to ideally disable indexing content, but still titles + custom fields to excerpts function.

  10. Hi Mikko,

    I have an customer that haven´t updated his site for 2 years. When he updated to the latest version of all plugins plus wordpress, Relevanssi stopped working. I have indexed again and still don´t work. Any ideas? Test searching on the site for example ac/dc, metallica or kiss.

    1. Peter, something’s wrong with the theme. If I search for “live in las vegas”, I get this as the search URL with no results:

      However, if you drop the dgwt_wcas part off, you get more results:

      That’s coming from Ajax Search for WooCommerce, so I’d start by disabling that plugin; it may be it’s not compatible with Relevanssi at all. Removing this finds you three results! But drop the post type restriction, and you’ll find 15 pages of results:

  11. Thank you Mikko for your reply.
    I have deactivated the Ajax search, and I have indexed again. There is no big difference. I know their is lots of Kiss albums on the site and it´s only showing 2.

  12. Hi Mikko,

    Is the code ‘add_filter( ‘relevanssi_index_content’, ‘__return_false’ );’ still valid in WP5, PHP7 and Relevanssi 4.3.3. ?

    I used it but no effects. I have 340.000 posts so my re-index took 22 hours.


    PS: I’ve red this page, you are a patient man.

    1. Yes, it’s still valid. Your site has about 300k posts too much for Relevanssi, so I would just recommend not using Relevanssi at all with those kinds of numbers. Even if you block the content, it’s still going to be unpleasant, there’s no way around that.

  13. Hi Mikko,
    i am not sure this is right place but i have used this solution on my page and its working. But i am looking for solution that search bar displays product tags when typing not products. Is it even possible?
    Thank you for your work.

    1. Relevanssi Premium can return product tags as results instead of products. However whether that works or not depends on the solution you use to display the live results, as that’s not a Relevanssi feature.

    1. Danish, have you added the code to disable the title indexing and have you rebuilt the index afterwards? If you look at the posts with the Relevanssi debugger (Settings > Relevanssi > Debugging), does the title content appear there?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.