• Resolved wordmax

    (@wordmax)


    We want to over-ride the themes default search results page title which is “Search Results for (keyword)” to a custom phrase like “You searched for (keyword)”. I guess this is a function of the search.php for the theme but thought I’d ask you the search guru if you know of a code snippet we can add to Snippets plugin to just over-ride the theme default search page title with a custom search page title.

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    All right, I am more than happy to help if I can. Usually these texts are either hard-coded to the results page, or there is an option somewhere under the theme settings which may allow you to change that.

    Either way there is little to no chance of using a code snippet to change it I’m afraid. If it’s hard coded, then maybe the gettext hook could work, but I am not sure:

    add_filter( 'gettext', 'my_custom_gettext', 10, 2 );
    function my_custom_gettext( $translation, $text ) {
    
    	if ( $translation == 'Search Results for' ) {
    		return 'You searched for';
    	}
    
    	return $translation;
    }

    This is a very wild guess, but worth trying.

    All the best,
    Ernest

    Thread Starter wordmax

    (@wordmax)

    Thanks very much, appreciate the help. I tried it but unfortunately no luck. The theme devs said to use the Loco translate plugin to over-ride the PO language file. Was hoping to avoid using another plugin just to do that but maybe it’s the only way without manually editing the language file on the theme which would end up being overwritten with theme updates anyway.

    Thanks again

    Plugin Author wpdreams

    (@wpdreams)

    Hmm, that is unfortunate, it is hard coded then. If you find the exact string though in the .po file, then there is still hope the code above may work.

    I just guessed what the string is on line 4, but it could be a bit different, and in that case the code will not work.

    All the best,
    Ernest

    Thread Starter wordmax

    (@wordmax)

    Looks like there are multiple files in the Blocksy theme that contain the phrase “Search Results for %1$s” so I tried manually changing those on various pages, including the /languages/blocksy.pot file with no effect on the front-end search results page title.

    Finally, it worked by editing the elements.php file. I tried changing the phrase “Search Results” to “You searched” in the php file named elements.php and it worked. It was the only file needed to change in order to customize the search page title text.

    …/wp-content/themes/blocksy/inc/components/hero/elements.php

    Of course these changes will be overwritten since I don’t have a child theme but it’s easy to change back again.

    Not sure what you meant by line 4 on the code regarding correct string to use.

    Appreciate your help and suggestions. Thanks

    Plugin Author wpdreams

    (@wpdreams)

    Okay, that may help. Maybe this:

    add_filter( 'gettext', 'my_custom_gettext', 10, 2 );
    function my_custom_gettext( $translation, $text ) {
    
    	if ( $translation == 'Search Results for %1$s' ) {
    		return 'You searched for %1$s';
    	}
    
    	return $translation;
    }

    This is still just a very wild guess.

    All the best,
    Ernest

    Thread Starter wordmax

    (@wordmax)

    Wow… Awesome! That works great.

    Really appreciate your help.

    Thank you!

    Plugin Author wpdreams

    (@wpdreams)

    Fantastic ??

    I will mark this as resolved then.

    Feel free to rate the plugin if you like it, it’s greatly appreciated.

    All the best,
    Ernest

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to customize search results page title? “Search Results for (keyword)?’ is closed to new replies.