This is just driving me crazy. I cannot get wp to return the home page/url link. I have tried various combinations of

<?php echo esc_url( home_url( '/' ) ) ?>
<?php echo esc_url( bloginfo( 'url' ) ) ?>
<?php echo home_url() ?>

But they all return the current page. In this case a page with attached queries.

Now I should mention that 1. I am not using the loop. I have not yet got to that stage though I did write it in to test this problem. 2. I have registered custom search queries.

function add_query_vars($aVars) {
    $aVars[] = "search";
    $aVars[] = 'special';
    return $aVars;

add_filter('query_vars', 'add_query_vars');

The problem only seems to occur in search.php when these custom queries are in use. As you have probably guessed the returned home url is always .../wp-install/?search=foo&special=bar.

Is there any way around this problem?

  • Any of those should work, though the middle one is deprecated. Post your code in context. I can't tell what you are doing. – s_ha_dum Aug 22 '13 at 13:04

home_url() uses get_home_url() which in turn uses get_option( 'home' ) to retrieve the home url. The code in get_option() includes this:

// If home is not set use siteurl.
if ( 'home' == $option && '' == $value )
    return get_option( 'siteurl' );

I didn't unwind all the previous code in the function, but it seems likely that under some circumstances get_option( 'siteurl' ) does not match home_url(). Apparently, you found one of those circumstances. Try using site_url() in this case.

| improve this answer | |
  • I ended up stepping through with the debugger (Don't know I didn't do it earlier) and found the problem. It ended up being a script set for the wrong id. – Twifty Aug 22 '13 at 14:16
  • If you have the time, please post your solution as an answer and accept it so others can learn from it and so the question will have an answer. – Charles Clarkson Aug 22 '13 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.