WordPress.org

Forums

[resolved] Bug? site_url giving me wordpress address (10 posts)

  1. complex_confusion
    Member
    Posted 4 years ago #

    I find it very hard to believe this is a bug, so I'm asking if anyone else knows what's going on.

    When using the default buddypress template, the name of my blog should be linked to the blog's address, zarathud.org. IN FACT, it was linked to the wordpress address, zarathud.org/something/wordpress/

    I fixed this by making a child theme with an edited header.php, but I'd like to pursue the original problem.

    The default copy of bp-default's header.php used site_url() to get the blog's address. According to the wordpress documentation, that should have been correct. However, that returned zarathud.org/something/wordpress instead of just zarathud.org.

    I fixed this by using bloginfo( 'url' ), but I gather that bloginfo doesn't return https in situations that require it, and siteurl() is supposed to be better.

    thanks for any feedback. Tell me if you think this really is a bug, and I'll report it. However, it's such a prominent feature of the default template that I find that improbable.

  2. Mossack Anme
    Member
    Posted 4 years ago #

    site_url() is the "site url", and it will detect the real wordpress install folder.
    bloginfo() is the "blog info", and it will load the "blog info" from database.

    CMIIW

  3. complex_confusion
    Member
    Posted 4 years ago #

    Mossack, sorry to argue, but the documentation says that site_url should be getting the URL for the current site, not the URL for the install folder. So either the documentation's wrong, the function's buggy, or it's just acting weird in my setup.

    I think that in your personal blog, you may have the WordPress Address and the Blog Address set to the same URL. For my blog, I want WordPress to be in a different directory than the top level of my domain, so the two are different.

    I rather knew that bloginfo() is the "blog info" but thanks, anyway.

  4. ClaytonJames
    Member
    Posted 4 years ago #

    Approaching it from a purely empirical perspective,

    A) "The site_url() template tag retrieves the site url for the current site"

    B) The siteurl being retrieved is located in the database at: wp_options > option_name > siteurl > option_value > http//www.yoursite.com

    C) option_value > http//www.yoursite.com, is determined by what you placed in the URL settings in the General Settings sub-panel. If that information contains a sub-directory, that too will be written to the option_value.

    D) When <?php $url = site_url(); ?> asks for the value of wp_options > option_name > siteurl > option_value, what will be returned will or will not contain a sub-directory depending on what you placed in the URLs in General Settings.

    Should any of those statements be thought of as assumption rather than observation? Is my own thinking flawed on this one?

  5. Mossack Anme
    Member
    Posted 4 years ago #

    Check out your http://YOURBLOGURL/wp-admin/options.php to see the whole option value. ^^

  6. complex_confusion
    Member
    Posted 4 years ago #

    Clayton, I believe all of those are the same assumption -- that site_url() is behaving as designed and documented. I think that's a good assumption. However, I'm seeing different behavior, and I'm not certain if that's because of a failing in site_url(), mistakes in the documentation -- and in the use! -- of the tag, or just a situational oddity caused by something else on zarathud.

    Mossack, yes, in General Options I've set the WordPress Address to zarathud.org/something/wordpress, and the Blog Address to zarathud.org. The All Options page (options.php) reports "home" to be zarathud.org and "site url" to be zarathud.org/something/wordpress.

    Mossack, correct me if I'm wrong but you seem to be saying that because All Options reports the WordPress Address to be the "site url" then that's what site_url() should return. The documentation disagrees with that, and doing so breaks the link in the header. (never mind the details, but clicking on zarathud.org/something/wordpress doesn't take you to the wordpress install directory; it tries to take you to a post with a name similar to something/wordpress.)

  7. ClaytonJames
    Member
    Posted 4 years ago #

    Clayton, I believe all of those are the same assumption -- that site_url() is behaving as designed and documented. I think that's a good assumption.

    It's not an assumption. And, in your own words, "site_url() is behaving as documented".
    The function site_url() is retrieving the data from siteurl > options_value in the database. That value was put there by entering a string in General Settings. If that string includes a sub-directory name, it too will be retrieved.

    Home and siturl are not the same option in the database.

    wp_options > option_name > siteurl > option_value.....
    wp_options > option_name > Home > option_value.....

    They are not the same. So wouild it be safe to say that at this point that site_url() is going to return the vaule of this?

    wp_options > option_name > siteurl > option_value..... including your sub-directories (if present).

    Just looking at your source code, I see several varieties of confusion for a novice like myself.

    //zarathud.org
    //zarathud.org/website/
    //zarathud.org/resources-sw/wordpress/wp-content
    ...etc...

    You appear to be serving from root, but it also appears as though wordpress could actually be installed two sub-directories deep(?); //zarathud.org/resources-sw/wordpress/

    Mossack, correct me if I'm wrong but you seem to be saying that because All Options reports the WordPress Address to be the "site url" then that's what site_url() should return. The documentation disagrees with that,

    I don't presume to speak on Mossack Anme's behalf, but I can't find where the documentation disagrees with that. Don't confuse "siteurl" with "Home" if the two are different. options.php will reveal both.

    Wow, if I'm missing something that could really help you, I'm sorry, but I just don't see it yet.

  8. Mossack Anme
    Member
    Posted 4 years ago #

    Hmm. I don't work for Automattic, so I prefer to find the real setting. You placed your wp folder two subfolder below your root, right? Hmm, seems a deep differencies. Have you edited the .htaccess about RewriteRule between # BEGIN and # END WordPress ?

  9. complex_confusion
    Member
    Posted 4 years ago #

    Clayton,

    Sorry, but no, I wasn't saying that site_url was behaving as documented. It seems to be behaving the opposite of documented -- but I doubt my judgement in this case enough to look into it more.

    Just looking at your source code, I see several varieties of confusion for a novice like myself.

    //zarathud.org
    ...
    //zarathud.org/resources-sw/wordpress/wp-content

    Yes, I have WordPress installed 2 directories deep, and (in answer to your question, Mossack) have the top-level index page & .htaccess edited to match. Pretty standard for anyone who doesn't want wordpress installed in the top level directory. Sometimes I wrote "something" or "website" instead of "resources-sw" just because I didn't want to write my directory structure in the forum, thanks.

    The documentation starts out without giving us any extra info: "retrieves the site url for the current site." The Example seems to make clear that we're talking about the blog address and not the wordpress install directory. But not perfectly clear.

    And the options.php page (and the database itself) doesn't help by using "site_url" to refer to the wordpress install directory and "home" to refer to the respective locations. bleah!

    Which finally brings us back to the real question. site_url() is used to link the blog name in the header to the blog, giving you a broken link if the blog URL & install directory aren't the same! So either site_url() isn't correct or some other function should be used. But what function? blog_info() will give me the correct URL but I'm not sure about whether it will give me the correct protocol.

  10. complex_confusion
    Member
    Posted 4 years ago #

    ah.

    I've been working with the bp-default theme all this time.

    I just looked at the (more recent) twentyTen theme and see that its 'header' banner avoids using site_url:

    <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>

    home_url() is the tag to use.

    I'll put in the request that bp-default be updated to match. That'll fix the problem for anyone else installing WP (and BP) in something other than top-level dir. Thanks for the help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags