• Resolved ejm

    (@llizard)


    I am using a Twenty Twelve Child theme and would like to customize the search results. In searching for the answer, all of them say to copy Twenty Twelve’s search.php into the child folder and alter it from there.

    But surely there is a way to do this in the child theme’s functions.php?

    I would really rather let people who actually understand coding do it and if the search.php in Twenty Twelve has to be updated for security reasons, the search.php will automatically be updated in my child theme.

    This is the only part (ie: cosmetic part) of Twenty Twelve’s search.php that I would like to change:

    <div class="entry-content">
    <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentytwelve' ); ?></p>
    <?php get_search_form(); ?>
    </div>

    I’m guessing that I could use gettext for the words, but I do not understand what the numbers are in the examples shown. I don’t know enough about coding to even know how to search for what the numbers mean.

    But I would also like to remove “get_search_form();” from the results. The search form is already on the sidebar.

    https://codex.www.ads-software.com/Plugin_API/Filter_Reference/gettext

    Not that I know what a hook is, but is there a hook for the search results? Can I use that somehow? Something along this lines:

    function display_no-result() {
    	if ( is_search('no-result') ) {
    		echo '<div class="entry-content">
    <p><?php _e( 'There are no matches. Unfortunately, the search is quite literal. Please check your spelling and try again using the search box on the sidebar.', 'twentytwelve' ); ?></p>
    </div>';
    	}
    }
    add_action( 'twentytwelve_search-no-results-hook_if-there-is-such-a-thing', 'display_no-result');

    Thank you for any help you can offer.

    E Morris,
    e t h e r w o r k [dot] n e t [slash] b l o g
    (no link because I don’t want to suffer through a malicious bot attack again)

Viewing 1 replies (of 1 total)
  • Thread Starter ejm

    (@llizard)

    Please excuse me for replying to myself. I have come up with a rather inelegant solution on my own and am really hoping that there are no other instances of “Nothing Found” on the site that will be changed.

    I removed the search box from the sidebar and replaced it with a link to mywordpress/?s. And this is what I added to the child’s functions.php (thanks to ronangelo for writing a page on gettext in layman’s terms – I tried to understand the WPcodex, I really did….)

    /*...............
    search results page
    ...............*/
    // thanks to https://ronangelo.com/change-or-translate-text-on-a-wordpress-theme/
    function mychanged_text( $change_text ) {
    	if ( $change_text == 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.' ) {
    		$change_text = 'If there are no results with your search, please check your spelling and try again.';
    	}
    	return $change_text;
     }
    add_filter( 'gettext', 'mychanged_text', 20 );
    
    function mychanged_text2( $change_text2 ) {
    	if ( $change_text2 == 'Nothing Found' ) {
    		$change_text2 = 'Search Me';
    	}
    	return $changed_text2;
     }
    add_filter( 'gettext', 'mychanged_text2', 20 );

    It’s with reluctance that I am marking this “resolved” because it doesn’t really answer my initial question. I still have no idea what the “20” signifies, nor do I know what search terms to use to find this out. (Also, there MUST be a way to alter only the search results page using the child’s functions.php)

Viewing 1 replies (of 1 total)
  • The topic ‘how to change search results in child theme using child's functions.php’ is closed to new replies.