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

  • rdissell

    w0w, great filter. Seems simpler then the code I’m using 🙂

    Bryan

    • Manish

      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?

      • Don’t set the weight, use the filter described in this post.

  • Daniel Hay

    This filter doesnt seem to work. I still have results based off post content. Im running 1.6 Premium.

    • Have you re-indexed the database after adding the filter?

  • Cristi Stanciu

    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.

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

  • How can I exclude images from showing in the search results?

    • Jason, do you mean attachments? If so, just don’t index them.

      • I mean images I have in the posts. Is that the same as an attachment? And how do I not index them?

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

          • 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! 🙂

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

          • 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!

          • Yes. This is explained in both the User Manual and the plugin info page on the WordPress.org repository, though…

          • 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!

          • It’s mentioned right in the installation instructions: http://wordpress.org/extend/plugins/relevanssi/installation/

            Also, if the instructions don’t mention widgets, I think it’s a safe bet to assume there’s no need to do anything about widgets, ie. use the search widget your theme already has…

          • 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!

  • José Costa

    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?

    • Yes: just wrap them in the [noindex] shortcode.

      • Martin Lowe

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

        • There’s really nothing else to it. [noindex]This text will not be indexed.[/noindex] Yes, it does work in the free version.

  • Manish

    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?

    • Did you reindex the database? The code doesn’t work until you do. You don’t need Premium, this works with the free version just as well.

      • Manish

        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?

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

  • Kim

    Can I just past this into my custom css box?

    • No, you can’t, because this is not CSS.

      • Kim

        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

        • Take the code above, add it to the functions.php in your theme, rebuild the index. Done.

          • Kim

            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

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

          • Kim

            How do I edit my search results template for thumbnails? I’ve looked and don’t see it.

          • I don’t know, it depends on which theme you are using. If you have a premium theme, ask the theme support.

  • Pablo

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

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