searchform.php my search form looks like this:
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <div> <input type="text" placeholder="<?php _e('Type something and hit enter...', 'wbs'); ?>" name="s" /> </div> </form>
However, I noticed that the search doesn't work as intended, the
?s= parameter isn't added to the home URL but rather to the current URL.
So, when I'm on the single post page, instead of
http://example.com/?s=term I'm getting
http://example.com/post-name/?s=term. Similar results while searching from archives and pages. Searching like this obviously doesn't work.
What's more, if I completely remove
searchform.php I'm getting the same results so it looks like
home_url() just doesn't return the correct URL. I have permalinks set up to Post Name.
Funnily enough, simply running
<?php echo esc_url( home_url( '/' ) ); ?> in other files (e.g.
footer.php) always returns
http://example.com/ as expected.
Any ideas why this is happening? Am I missing something?