How do you create links in a template that will work properly in sites created from the template?

I just started using the New Blog Template plug-in, and it seems to bring all settings and content over just fine. On some pages, I had relative links to other pages on the site (for example, to link to my Contact page I used: <a href="/contact/>Click here to contact me</a>). When the new site was created, those links went to the Contact page in the original template site (which is in my root directory), instead of going to the Contact page in the new site. If I manually change the links to absolute URLs, they work properly. Is there a way to create them in the template so they will work properly when a site is created from it?

  • DavidM
    • DEV MAN’s Mascot

    Hi pzuckermanaz and welcome to WPMU DEV!

    In testing it out myself I really couldn’t see a way around that. It actually just has to do with the way WordPress Multisite works, relative urls on sub-sites go to the main site.

    As it stands, the plugin merely copies the content right over to the new blog without actually touching that data, so there’s not really a way to change those urls before the copy to compensate for the new blog.

    Ultimately, I would think the solution would be to somehow get relative urls on sub-sites pointed to those sub-sites instead of the main site.

    If it helps, domain mapped sub-sites should point properly. I haven’t tried a sub-domain install to see if they would to likewise.

    Cheers,

    David

  • pzuckermanaz
    • New Recruit

    Hi Marika – Thanks for the suggestion. I actually have the closing quotes in the hrefs on the site, they were just left out of my posting. So far, I think David has the only answer that works – thanks David. My goal is to do what David suggested (incorporate relative urls that will work on the sub-sites) but I haven’t figured out how to do it yet. Still hoping someone has this answer.

  • Mason
    • DEV MAN’s Sidekick

    Hiya,

    Are you entering the relative link into a WordPress post/page area? Oddly, remember having this issue in the past, but just set up a test and the relative URL copied over correctly using the New Blog Templates plugin.

    A couple things you could try:

    On a Multisite install using sub-domains you may be able to remove the protocol and domain name from URL strings by placing the following in a file (name it whatever ya like relative_urls.php for example) and putting the file in wp-content/mu-plugins

    <?php
    function make_href_root_relative($input) {
    return preg_replace('!http(s)?://' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
    }
    ?>

    I’ve used this on single installs before, but not multisite. You also don’t want to use it on sub-directory multisite as it may interfere with the actual various sub-sites.

    Other options you could try:

    http://plugins.trac.wordpress.org/wiki/RelativeLinks

    http://wordpress.org/extend/plugins/absolute-to-relative-urls/

    http://engipress.com/2011/01/08/wordpress-relative-urls-plugin/

    Hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.