Consider the following code:
<form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
home_url()
is a Wordpress function that retrieves the home URL for the current site. When called with an optional $path
argument, it returns the Home URL with the optional $path
argument appended.
Here's the function definition (from wp-includes/link-template.php
L#1959):
function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
$orig_scheme = $scheme;
if ( empty( $blog_id ) || !is_multisite() ) {
$url = get_option( 'home' );
} else {
switch_to_blog( $blog_id );
$url = get_option( 'home' );
restore_current_blog();
}
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] )
$scheme = 'https';
else
$scheme = parse_url( $url, PHP_URL_SCHEME );
}
$url = set_url_scheme( $url, $scheme );
if ( $path && is_string( $path ) )
$url .= '/' . ltrim( $path, '/' );
return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
}
Basically, there's nothing in this function that would return a random URL out of nowhere.
When situations like this occur, the best thing to do is to grep
your code for clues.
Run this in a shell in the Wordpress root installation directory:
grep -nr "http://randomurl.com"
This will list all the occurences of http://randomurl.com
in your code-base and show the files that they appear in. If there are multiple occurrences, you can use a bit more advanced search (using command line options such as awk
) to see which one's actually causing troubles.
Note: I know this has already been solved, but this might be useful for future visitors, so I'm posting it as an answer :)
<form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
. Because theaction
attribute is what defines the website/URL the user is taken to when the search query is submitted.get_home_url()
here to see what can influence it's output.