Support » Networking WordPress » Get multisite network base url?

  • I can’t find the answer to this anywhere… hopefully I haven’t missed it somehow. I need to find a way to get the URL for the main parent blog for use in themes in the sub-blogs.

    I am writing a theme/plugin package designed for multisite network blogs with a subdirectory configuration. There are several points where I need to include files that are in the “base” installation, but that will be used by a theme in the sub-blog.

    As an example, the template file located in http://www.domain.com/wordpress/blog2 needs to include the file http://www.domain.com/wordpress/wp-admin/includes/post.php.

    Normally, I would use a relative path and add the site url to it, like so:
    <?php $incPath = get_bloginfo('url') . '/wp-admin/includes/post.php'; ?>

    However, because it’s network installation, get_bloginfo('url') returns http://www.domain.com/wordpress/blog2, and so the include command doesn’t work.

    Is there any way to pull the URL of the parent blog (base, dashboard, main, I’m not sure what the proper terminology is)?

    Thanks!

    [moved to Multisite]

Viewing 15 replies - 1 through 15 (of 17 total)
  • You could either do a custom SQL query against the wp_site table (for the ‘domain’ field) or you could use the function switch_to_blog(1) and restore_current_blog() before using get_bloginfo(‘url’).

    Hmm, I think I may have left out important info… I am using WordPress 3.1 with the built-in network system, rather than using WPMU. Aren’t the functions separate?

    I’ll give that a shot though. Thanks!

    WPMU became WordPress MultiSite, which is the built-in network system.

    I am writing a theme/plugin package designed for multisite network blogs with a subdirectory configuration. There are several points where I need to include files that are in the “base” installation, but that will be used by a theme in the sub-blog.

    you know, I’m trying to figure out why you’re doing this and I can’t come up with anything.

    And the url of the main site is the site_url. not blog_url.

    Sorry, where am I looking for site_url vs. blog_url? What I was using was get_bloginfo('url'), not specifying site/blog.

    The installation is part of a low-level project management system. The multisite installation is set up as mydomain.com/client/project, with client being the main parent blog which has multiple project blogs underneath it.

    One of the features is a front-end posting system, for which I activated TinyMCE so people could use a visual editor without dealing with the WordPress back end. This needs the include I mentioned above, wp-admin/includes/post.php.

    Normally I include a <base> tag in my header file and then reference all includes/images/links/etc. as relative to that. I generally set that as <base href=<?php bloginfo('url'); ?>" /> because then the theme doesn’t need to be customized for every installation. However, because the sub-blogs are virtual installations, there is a mydomain.com/client/wp-admin folder, but not a mydomain.com/client/project/wp-admin folder, and so the include fails and the front-end post doesn’t load correctly in the sub-blogs.

    What I was using was get_bloginfo(‘url’), not specifying site/blog.

    and that gets the blog you are on. what the admin area calls a site.

    You said you wanted the main site. that is the site_id.

    However, because the sub-blogs are virtual installations, there is a mydomain.com/client/wp-admin folder, but not a mydomain.com/client/project/wp-admin folder, and so the include fails and the front-end post doesn’t load correctly in the sub-blogs.

    you know all subsites pull from the same code too right? that’s how they pull tinymce in the subdomain edit areas.

    site_id doesn’t return the URL, though, it returns the Site Title from the general settings page. wpurl returns the URL, but it also returns the URL of the subsite if called as part of a subsite. Same problem.

    you know all subsites pull from the same code too right? that’s how they pull tinymce in the subdomain edit areas.

    Yes. That’s why I’m having trouble. It is using the same code — <base href=<?php bloginfo('url'); ?>" /> — for both the main site and the subsite. Because that code returns something different in a subsite but the file it should be pointing to is not different, it doesn’t work.

    Obviously there’s a better way to do it, because as you said it’s being done on the back end. I simply don’t know what that better way is, which is why I asked the question in the first place.

    Sometimes everyone in this forum is so busy questioning why you are doing something, that some simple answers would go a long way…

    I am facing the same question (I just want it, ok 🙂

    Here is what I found:
    echo get_site_url(1);
    would return the site url for the main site (which is the root)

    then, I wanted the full URL (which in my case included some “?otherthingid=somerandomid” on the end of the URL, which nothing else was really pulling. So I did this:

    echo get_site_url(1).$_SERVER[“REQUEST_URI”];

    Hope that helps someone else.

    esmi

    (@esmi)

    Forum Moderator

    Try posting a new topic instead of tacking onto someone else’s topic from a month ago.

    Really? Why? It is the exact same topic.

    In my experience, the fewer threads about the same topic, the better in a forum, no?

    esmi

    (@esmi)

    Forum Moderator

    On this forum? No.

    Well, despite all the bickering, jskov’s solution worked perfectly for me. In my case, I simply needed to echo the blog url for a multisite setup, but bloginfo(‘url’) and bloginfo(‘siteurl’) were returning a lone forward slash, nothing else.

    //ex.
    echo bloginfo('url');
    
    //returned
    /

    I tried echo get_site_url(2).$_SERVER[“REQUEST_URI”]; and it worked perfectly. I dug a little deeper and found that I should have been using
    get_bloginfo(‘url’) instead.

    //ex.
    echo get_bloginfo('url');
    
    //returned
    http://subdomain.domain.com

    …also site_url() accomplishes the same thing. So to recap:

    //ex.
    echo get_bloginfo('url');
    //returned
    http://subdomain.domain.com
    
    //ex.
    //note bloginfo() returns a value, so echo is unnecessary.
    bloginfo('url');
    //returned
    /
    
    //ex.
    echo site_url();
    //returned
    http://subdomain.domain.com

    The scope of this project got changed considerably so my interest is academic at this point. However:

    @jskov: the get_site_url() command seems to do the trick! Somehow I hadn’t caught the option to pass the blog ID when calling that function. Is it safe to assume that the main blog will always be #1?

    @pszeinert: the bloginfo('url') command actually includes the echo function built in, so it should also work if you just remove your echo command. In other words, echo get_bloginfo('url'); and bloginfo('url'); should give you the same results.

    @jnorion: For whatever reason with my setup, bloginfo(‘url’) only returns “/” (without quotes). If you look at my code above, I don’t have an echo before bloginfo(‘url’). With echo it returns nothing (which I know), but without echo it only returns the forward slash.

    echo site_url(), echo get_bloginfo(‘url’), and bloginfoI(‘url’) should all return the same value, but I am not able to get the expected output from bloginfo(‘url’).

    I have it working for my purposes now using site_url(), and this is really a discussion about which way to skin a cat. Bottom-line, my cat is skinned. Hope this helps other entrepreneurial coders.

    Ah, ok. I was looking at your first bit of code, which was mixing the two. That’s interesting though, I can’t replicate that one myself in my current project.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Get multisite network base url?’ is closed to new replies.