sage icon indicating copy to clipboard operation
sage copied to clipboard

URLs broken when install is >= 2 subfolders deep

Open jfsebastian opened this issue 14 years ago • 57 comments

I've been trying to create a child theme in my wordpress which is installed in a custom directory (/vendor/wp in my case) and configured to work by default from / .

In the functions roots_scripts() in roots-scripts.php the value of $base is right, but it seems that the function wp_register_script adds automatically the base wordpress directory and hence duplicates the first part of the URI, in my case it converts it to /vendor/wp/vendor/wp/wp-content/themes/roots/js/[...]

I'm not enough familiar with the URI functions of wordpress, but it seems that is necessary a function like get_template_directory_uri() but relative to the install directory of wordpress.

By now I'll bypass the value of $base in the parent theme.

Thanks for a wonderful product.

Regards from Spain.

jfsebastian avatar Apr 12 '12 16:04 jfsebastian

latest commits fix your issue

retlehs avatar Apr 12 '12 16:04 retlehs

Thanx, GREAT!!!

jfsebastian avatar Apr 12 '12 16:04 jfsebastian

Still doesn't work. Now it's meshing up even the CSS URIs that were working.

wp_register_script() is still adding the Wordpress installation URI to the beggining so it duplicates part of the address.

Or I'm doing terribly wrong something...

jfsebastian avatar Apr 12 '12 19:04 jfsebastian

are you going from a fresh install or are you cherry picking commits? if you're picking out the commits, you're missing something

retlehs avatar Apr 12 '12 19:04 retlehs

I've just deleted the child theme, deleted roots, and reupload it complete. Without using the child theme it shows right modernizr & jquery (which are loaded in the header.php) but it duplicate the install path part of the URI.

You can see it in http://offworld.es Without creating the child theme scripts and CSSs are pointing to /vendor/wp/vendor/wp/css/ or /vendor/wp/vendor/wp/js/

I've also tried 2 new fresh installs of wordpress and the theme. One in http://xenovision.es/ . URIs are pointing allright out of the box to /css and /js (but I didn't put them there) The other in http://xenovision.es/wordpress/test/empty/ URIs are pointing to unexistent URIs repeating the install path of wordpress in the URI like: /wordpress/test/empty/wordpress/test/empty/css/ and /wordpress/test/empty/wordpress/test/empty/js

Still having the wp_register_script() repeating issue. Is this or a problem with .htaccess

jfsebastian avatar Apr 12 '12 21:04 jfsebastian

is this in your code? 69a42d05df7ad9bec46e4c8d2c87e9a981d44634

retlehs avatar Apr 12 '12 22:04 retlehs

Yes. I do have the "Terrible workaround" and the rest of changes in that commit.

I feel lost. And at this time of night I feel terrible about beeing wasting my, and manly your time.

jfsebastian avatar Apr 12 '12 23:04 jfsebastian

@jfsebastian sorry for all the problems. Pretty sure I know what's going on. It's a bug caused by your slightly unusual WordPress setup with a custom core file location (which we don't really support) and being installed in a subdirectory.

preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);

This line in the "terrible workaround" checks if the first 2 subdirectories match each other. Obviously in this case, that isn't true since it's vendor/wp so it's still doubling up. I think I can fix this with a much more flexible solution.

Do you happen to know what WP function will return that vendor/wp path? I could update the function to check for the duplicate of that and then it would work.

swalkinshaw avatar Apr 12 '12 23:04 swalkinshaw

Well. I'm not really into the URI functions of Wordpress core, but today I've tested that get_template_directory_uri() seems to get it properly, but when using wp_register_script() was adding again the WP install path; at least in the slightly older version I was using this afternoon when opened the issue.

I'll keep looking to it for a while, in case I find something useful, but it's kind of late here in Spain.

BTW if the solution is more elegant than the pre-existent it's OK, but don't think the unusual installations of WP like mine deserve to bother so much. In fact it could be easier to simplify my installation.

Anyway, thankyou for the super-fast response and the superb work on the theme.

jfsebastian avatar Apr 12 '12 23:04 jfsebastian

Testing simply on the roots-scripts.php I've checked that in fact wp_register_script() is always adding the path of wordpress installation to the beggining. That's odd. How can you get an absolute path like /css or /js if that's true? The register function in the core of wordpress are not allowing absolute paths at all?

Can't think now of an easy solution.

jfsebastian avatar Apr 12 '12 23:04 jfsebastian

You're correct that wp_register_script() always prepends the WP installation path. Roots just gets around this with our relative URL cleanup and then the URL rewriting.

I'll take a look at this when I get some time. But if you want a quicker solution than changing your setup, just modify that work around preg_match_all to suit your case. Or just hard code it... Nothing wrong with that since it's your install.

swalkinshaw avatar Apr 13 '12 00:04 swalkinshaw

Yes, I'll do some dirty tricks to get it working for now. If I have the time and come up with something I'll share it.

jfsebastian avatar Apr 13 '12 00:04 jfsebastian

I'm having the same issue, but I'm not using child themes. If I install wordpress in a location such as localhost/mysite it works fine but when I install it on something like localhost/sites/mysite I get the wrong links for my assets:

<link rel="stylesheet" href="/sites/mysite/sites/mysite/css/style.css">
<link rel="stylesheet" href="/sites/mysite/sites/mysite/css/bootstrap.css">
<link rel="stylesheet" href="/sites/mysite/sites/mysite/css/bootstrap-responsive.css">
<link rel="stylesheet" href="/sites/mysite/sites/mysite/css/app.css">
<script type='text/javascript' src='/sites/mysite/sites/mysite/js/plugins.js'></script>
<script type='text/javascript' src='/sites/mysite/sites/mysite/js/script.js'></script>

weslly avatar Apr 13 '12 13:04 weslly

I'm not sure if i'm doing something wrong but I've commented this line and now it works

https://github.com/retlehs/roots/blob/master/inc/roots-cleanup.php#L90

weslly avatar Apr 13 '12 13:04 weslly

Same problem here, I downloaded the latest version of Roots yesterday and all the CSS and JS aren't working because of that: <link href="/sites/[subfolders]/sites/[subfolders]/css/style.css" rel="stylesheet">

[subfolders] being Lostmindy/blogosphere/BlahBlah

It's not a child theme.

Since I'm not a developper (I'm learning !), I don't know what to do for something like that.

(Sorry for the bad english and sorry if I'm doing something wrong by answering here ><)

EDIT : I deleted the get_template_directory_uri() in roots_scripts.php for now.

Lostmindy avatar Apr 21 '12 11:04 Lostmindy

Thanks for the reports. Definitely a bug then that happens when the install is >= 2 subfolders deep.

swalkinshaw avatar Apr 22 '12 14:04 swalkinshaw

renamed title to make more sense

retlehs avatar Apr 25 '12 20:04 retlehs

I downloaded the latest version of Roots NOW and all the CSS and JS aren't working.

my blog http://localhost/blogs/idiotinha/

Screenthot e .htacces here https://docs.google.com/open?id=0By-a1VRKi4mdQ2d0ZFRuWWhWdWs

<head>
  <meta charset="utf-8">

  <title>Idiotinha</title>

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="/blogs/idiotinha/js/libs/modernizr-2.5.3.min.js"></script>

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="/blogs/idiotinha/js/libs/jquery-1.7.2.min.js"><\/script>')</script>


    <link rel="alternate" type="application/rss+xml" title="Idiotinha Feed" href="http://localhost/blogs/idiotinha/feed/">
  <link rel="stylesheet" href="/blogs/idiotinha/wp-includes/css/admin-bar.css?ver=20111209">
<link rel="stylesheet" href="/blogs/idiotinha/blogs/idiotinha/css/style.css">
<link rel="stylesheet" href="/blogs/idiotinha/blogs/idiotinha/css/bootstrap.css">
<link rel="stylesheet" href="/blogs/idiotinha/blogs/idiotinha/css/bootstrap-responsive.css">
<link rel="stylesheet" href="/blogs/idiotinha/blogs/idiotinha/css/app.css">
<script type='text/javascript' src='/blogs/idiotinha/blogs/idiotinha/js/plugins.js'></script>
<script type='text/javascript' src='/blogs/idiotinha/blogs/idiotinha/js/script.js'></script>
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css" media="screen">
    html { margin-top: 28px !important; }
    * html body { margin-top: 28px !important; }
</style>

</head>

duard avatar Apr 25 '12 20:04 duard

Not sure if related to this bug: if you install wordpress + roots in http://localhost/mysite, the url to Home page in primary navigation will be http://localhost/ instead of http://localhost/mysite

weslly avatar Apr 25 '12 21:04 weslly

I am having a similar issue with local testing on Ubuntu. My folder is located at var/www/sitename, i have a fresh install of wordpress and roots but it's looking for the css, js and img files at the site root instead of the theme root. I temporarily fixed this by copying those folders to root of the site.

Geroblee avatar Apr 26 '12 17:04 Geroblee