WordPress.org

Ready to get started?Download WordPress

Forums

SEO searching (3 posts)

  1. JayBro
    Member
    Posted 6 years ago #

    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.

  2. Doodlebee
    Member
    Posted 6 years ago #

    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 :)

  3. Dgold
    Member
    Posted 6 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic