Site logo

Archived topic

Change language search

9 replies · Started by Liana Ghazarian on December 4, 2020

Viewing posts 1–10 of 10

Hi,

How can I change the text for search result pages, both positive and negative? My site is in armenian, but even if i change the wordpress language to armenian, the search results page are in english. I still have

Search results for 'fqsdqfsq'
Nothing Found
Sorry, but nothing matched your search terms. Please try again with some different keywords

Another option, maybe easier is how to remove any text from these pages?
I found this code in discussions and placed in in styles.css of the child theme, but no results. add_filter( 'gettext', function( $text ) {
if ( 'Search Results for: %s' === $text ) {
$text = '%s';
}

return $text;
} );

Thank you

add_filter( 'gettext', function( $text ) {
if ( 'Search Results for: %s' === $text ) {
$text = '%s';
}

return $text;
} );

Hi,

Can you try this instead?

add_filter( 'gettext', function( $text ) {
if ( 'Search Results for: %s' === $text ) {
$text = '%s';
}

return $text;
} );

It's basically the same except I've replaced all the curly quotation marks and with straight quotation marks '. It works on my end as shown here: https://share.getcloudapp.com/BluQZWk5

I think my You searched for text was comming from Breadcrumbs, not GP.

But I do still have this text in english

Nothing Found
Sorry, but nothing matched your search terms. Please try again with some different keywords.

Is there any way for me to have it in a different language

Hi there,

You can overwrite the no results template completely:

add_filter( 'generate_do_template_part', function( $do, $template ) {
    if ( 'none' === $template ) {
        $do = false;
    }

    return $do;
}, 10, 2 );

add_action( 'generate_before_do_template_part', function( $template ) {
    if ( 'none' !== $template ) {
        return;
    }
    ?>

    <div class="no-results not-found">
        <div class="inside-article">
            <h1>Nothing found.</h1>
            <p>Your custom text here.</p>
        </div>
    </div>
    <?php
} );

That way you can change the text or add it to it as much as you want :)

Hi Tom and Liana, apologies for hijacking this thread.

I just tried that code and it works great. However, the search form disappears, so is there any code I could add to make it reappear?

Thanks.

This worked perfect for me especially since I didn't want the search form that Baz mentioned.

I hava d related question though. Only the search page in my breadcrumbs is in english. How do I change the name of this generated page?

To add the search form, you can use this function:

<?php get_search_form(); ?>

As for breadcrumbs, it's likely that the plugin generating the breadcrumbs is automatically naming it - you may need to check with them.

Thanks a lot

No problem!

This archived topic is closed to new replies.