Customizing WP site search results

3 replies
Hi all,
Is there a simple method/plugin to customize the search results made on my site?
For example, instead of returning an empty page or no results found, return a custom message or call to action?

Thanks,
#customizing #results #search #site
  • Profile picture of the author rhinocl
    You need to find where the error message is generated in your theme and edit it (I remember in Atahualpa it is in index.php) or just add/edit the error template:
    Creating an Error 404 Page « WordPress Codex
    {{ DiscussionBoard.errors[9947346].message }}
  • Profile picture of the author emptee
    Hi mate,

    Depends on the theme - I'll show you how you could do it in twentythirteen and you can (hopefully) apply it easily enough to your theme

    First things first - check out search.php in the theme directory (if it uses it - otherwise look around for some string that is "near" the search results, some markup with an id tag is normally the best target...)

    Anyway - looking at search.php, there's a pattern:

    Code:
    <?php if ( have_posts() ) : ?>
    
    //stuff to show search results..
    
    <?php else : ?>
    <?php get_template_part( 'content', 'none' ); ?> // <-- this is interesting....
    <?php endif; ?>
    Cool - so this tells us that what we're looking for is in the content none template... which leads us to 'content-none.php'

    Which looks something like this..

    Code:
    <header class="page-header">
    	<h1 class="page-title"><?php _e( 'Nothing Found', 'twentythirteen' ); ?></h1>
    </header>
    
    <div class="page-content">
    <?php if ( is_home() && current_user_can( 'publish_posts' ) ) : ?>
    
    <p><?php printf( __( 'Ready to publish your first post? <a href="%1">Get started here</a>.', 'twentythirteen' ), admin_url( 'post-new.php' ) ); ?></p>
    
    <?php elseif ( is_search() ) : ?>
    
    <p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with different keywords.', 'twentythirteen' ); ?></p>
    <?php get_search_form(); ?>
    
    // ^^^^ This is where you could do whatever you like! I'd recommend something along the lines of... <?php do_shortcode("some form plugin shortcode"); ?>
    // that way you can change the form/optin/picture of a cat easily from within WP
    
    <?php else : ?>
    
    <p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', 'twentythirteen' ); ?></p>
    <?php get_search_form(); ?>
    
    <?php endif; ?>
    You could also change the get_template_part instead - but, IMO, changing the content-none is cleaner

    Cheers,
    Michael

    Originally Posted by IMPromocoder View Post

    Hi all,
    Is there a simple method/plugin to customize the search results made on my site?
    For example, instead of returning an empty page or no results found, return a custom message or call to action?

    Thanks,
    {{ DiscussionBoard.errors[9950063].message }}
  • Profile picture of the author voldamort
    you need to go into root into the theme files .... do what rhinocl is telling ... if you are using sublime editor just search all the files with the text and replace with your text ....
    {{ DiscussionBoard.errors[9962601].message }}

Trending Topics