WordPress.org

Support

Support » Plugins and Hacks » SEO searching

SEO searching

  • Hi there,
    I just wanted to post a solution I haven’t found on this site yet. It’s not the most clean solution but a very simple one. (it is not optimized either, but it gives a fair idea)

    I hated the ?s=searchword, so I wrote some javascript that puts a clean “search/searchword” in the url. Put this in your searchform.php in the template directory:

    <script type="text/javascript">
    	function doSearch() {
    location.href='/search/'+document.getElementById('s').value;
    	}
    </script>
    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/" onSubmit="doSearch(); return false;">
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" class="inputText" />
    <input type="button" id="searchsubmit" class="inputSubmit" value="Search" onClick="doSearch();" />
    </form>

    Preview here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Alternatively, you could just do this:

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <input type="text" value="<?php echo attribute_escape($s); ?>" name="s" id="s" class="inputText" />
    <input type="button" id="searchsubmit" class="inputSubmit" value="Search" />
    </form>

    Has the same effect – no extra script needed.

    Or, if you wanted default text to show up in the search field:

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <input type="text" value="Search Me!" name="s" id="s" class="inputText" />
    <input type="button" id="searchsubmit" class="inputSubmit" value="Search" />
    </form>

    Still works 🙂

    Weird, I just tested the search on my site.

    When I use the built-in WP Search Form that’s in the Kubrick theme, it sends me to the URL
    mysite.com/blog/index.php?s=schools

    but if I type the permalink
    mysite.com/blog/search/schools
    it works and gives the same search results page.

    So I think in my case, I only need to fix the Search Form to go to the better permalink in the first place, right?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘SEO searching’ is closed to new replies.