roots / sage

WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and a modern development workflow
https://roots.io/sage/
MIT License
12.74k stars 3.06k forks source link

URLs broken when install is >= 2 subfolders deep #395

Closed jfsebastian closed 11 years ago

jfsebastian commented 12 years ago

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.

retlehs commented 12 years ago

latest commits fix your issue

jfsebastian commented 12 years ago

Thanx, GREAT!!!

jfsebastian commented 12 years ago

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...

retlehs commented 12 years ago

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

jfsebastian commented 12 years ago

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

retlehs commented 12 years ago

is this in your code? 69a42d05df7ad9bec46e4c8d2c87e9a981d44634

jfsebastian commented 12 years ago

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.

swalkinshaw commented 12 years ago

@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.

jfsebastian commented 12 years ago

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 commented 12 years ago

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.

swalkinshaw commented 12 years ago

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.

jfsebastian commented 12 years ago

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.

weslly commented 12 years ago

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 commented 12 years ago

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

Lostmindy commented 12 years ago

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.

swalkinshaw commented 12 years ago

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

retlehs commented 12 years ago

renamed title to make more sense

duard commented 12 years ago

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>
weslly commented 12 years ago

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

Geroblee commented 12 years ago

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 commented 12 years ago

I'm assuming this has to do with the new rewrite rules. Missed a directory level somewhere or something. Going to see what i can come up with.

cellvia commented 12 years ago

i am also having this issue, using a localhost path, clean install of latest wordpress and latest roots... wesleys fix above (commenting out line 90 of roots-cleanup) works for me

gsonbuchner commented 12 years ago

Hello Ben,

I seem to be having a similar problem with my css and js

Current Config

WP 3.3.2 PHP 5.3.6 MAMP 2.0 Pulled the latest roots version 5-6-2012

I think the culprit is the way the path to my css shows up in index.php

the relative path should be just "wp/spwp" not "wp/spwp/wp/spwp" when I manually remove the extra wp/spwp I can connect to the css and js

My .htaccess file looks like if that helps.

BEGIN WordPress

RewriteEngine On RewriteBase /wp/spwp/ RewriteRule ^index.php$ - [L] RewriteRule ^css/(._) /wp/spwp/wp-content/themes/roots/css/$1 [QSA,L] RewriteRule ^js/(._) /wp/spwp/wp-content/themes/roots/js/$1 [QSA,L] RewriteRule ^img/(._) /wp/spwp/wp-content/themes/roots/img/$1 [QSA,L] RewriteRule ^plugins/(._) /wp/spwp/wp-content/plugins/$1 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wp/spwp/index.php [L]

Cheers, Greg

Biwer21 commented 12 years ago

I ran in to this error as well. I just spend two hours tweaking the .htaccess to try and figure out why wordpress/roots was deciding that the path to my css and js included /wordpress/subfolder/wordpress/subfolder, and found no solution.

The problem is putting the installation of wordpress in a subfolder of a subfolder on localhost. If you do a fresh install of wp, only one folder deep, you'll be fine. Temporary fix for now.

gsonbuchner commented 12 years ago

Thanks Biwer21, I installed a fresh wp only 1 folder deep, but had to refresh the permalinks to see the css. Working now. Thanks again.

Dermotholmes commented 12 years ago

me too, subscribing

kmlx commented 12 years ago

for all the folks who have this issue, a temporary workaround (no matter how deep the installation is):

remove all instances of get_template_directory_uri() from /inc/scripts.php

kmlx commented 12 years ago

Contact form 7 = lots of resources not found. CF7 duplicates the url: / sub1 / sub2 / sub3 / sub1 / sub2 / sub3 /

Above temp solution not working in this case.

retlehs commented 12 years ago

fixed by 1429e33933908aee4a5c4a3a92901c253a051ac7 - thanks @jamescostian

Lostmindy commented 12 years ago

Thanks you very much ^^

kmlx commented 12 years ago

Thank you for this kind sir.

retlehs commented 12 years ago

i've reopened this because it's now an issue again with 704ee09f2bf260257282e401e7b4dec13b66b208, which fixed #478

this issue will not be experienced as much as the other. to fix this issue for now, simply remove each mention of get_template_directory_uri() in inc/scripts.php

gik000 commented 12 years ago

i applied the fix and that made my roots working

ty

agillette commented 12 years ago

I ran into the same issue, but retlehs quick fix above worked for me. I will probably have to change it back once I go into production, but ... c'est la vie.

brucedav commented 12 years ago

Same issue here.. I have the latest commit and the html head paths for css are incorrect. Removing all references to get_template_directory_uri() in inc/scripts.php hasn't resolved the issue for me however..

brucedav commented 12 years ago

Some info on my setup. I have moved wp-content out of the wordpress folder and one level back ie

website/wp-content website/wordpress

The issue I experience is that the roots theme produces the wrong path for css and js scripts. It prints them as:

/wordpress/wp-content/themes/roots/ ect ect

instead of:

/wp-content/themes/roots/ ect ect

I've defined WP_CONTENT_DIR in wp-config.php to reflect the new location for the wp-content folder. See below:

define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content'

Whats weird is that if I call the get_template_directory_uri() function directly in header.php to define all the scripts the correct path is printed. But when this same functions is run under the roots_head() function the incorrect path is returned..

Weird right? Any ideas?

brucedav commented 12 years ago

Making some progress.... Looks like get_template_directory() is returning the correct results when run in both header.php and / or scripts.php, however when run in scripts.php in the below line of code /wordpress/ is automagically prepended... Hmmm....

wp_register_script('roots_main', get_template_directory_uri() . '/js/main.js', false, null, false);

The above outputs: /wordpress/wp-content/themes/roots/js.main.js (wrong...)

as an example... If I modify it too:

wp_register_script('/js/main.js', false, null, false);

The above outputs: /wordpress/js/main.js (wrong again...)

Anyone know why wp_register_script would prepend the output with /wordpress?

brucedav commented 12 years ago

Bit of a nasty hack but I have resolved the issue by replacing all references to get_template_directory_uri() in scripts.php with WP_CONTENT_URL and including /themes/roots to the path that follows.. ie

wp_enqueue_style('roots_bootstrap_responsive', WP_CONTENT_URL . '/themes/roots/css/bootstrap-responsive.css', array('roots_bootstrap'), null);

guilhermegualtieri commented 12 years ago

Hello, i was just having this issue right now and i ran through @retlehs last comment, simply replace all of get_template_directory_uri() inside /lib/scripts.php with '' and it should work! :)

Thanks

Macxim commented 12 years ago

Hello,

I don't really know exactly if it's the same issue but I think I have also a URL problem. For some reason, the images declared in the HTML are not loading when I am in a specific category. In my code, I call them like this in the HTML: < img src="../img/file.png" alt="" / >.

I am using WPML, so my URLs are generated like this. http://www.website.com/fr/ for French http://www.website.com/es/ for Spanish

So far, everything works well. However when I go to a post in a category, let's says http://www.website.com/es/category/my-post, images from the HTML —no problem with the one called in the CSS— won't load. Instead I get a very nice blue square with a question mark. I'm sure you are all familiar with this one :)

Oh and it seems the same thing occurs with the pagination and nothing to do with the language because my URL looks like this : http://www.website.com/category/page/2.

How can I solve this? Thanks in advance for your help!

leoj3n commented 12 years ago

@Macxim,

Try linking your images like

<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/file.png" title="" alt="" />

If that doesn't solve it, create a thread over at the Google group because I don't suspect your problem is related to this issue.

If you do create a new thread, duplicate your question and additionally include the result of secondary-clicking the blue square and selecting "Copy Image Address".

kmlx commented 12 years ago

@Macxim

try any of the following:

src="<?php echo get_stylesheet_directory_uri(); ?>/img/file.png" src="<?php echo get_template_directory_uri(); ?>/img/file.png" src="<?php echo get_theme_root(); ?>/img/file.png"

all of the above should work.

Macxim commented 12 years ago

@leoj3n @kmlx

Thank you both for the quick replies! Indeed it worked. Thanks for the tip. Sorry for polluting the thread with this unrelated issue. Next time I'll open one in the Google Group.

herkocoomans commented 11 years ago

I'm running into this issue too. I've got the latest roots theme (6.1.0 according to the style.css), running WordPress 3.4.2 on MAMP, set up as multisite in subfolders. I want to create a child theme of roots on my sandbox, and migrate it to the server later.

My site is localhost/wordpress/site2/, so the active theme is at wp-content/themes/roots-child. I'm getting 404 errors on the css and js files, not loading any of them. The path these point to are localhost/wordpress/site2/wordpress/site2/wp-content/themes/wp-child/xxx.xxx.

I've commented out the get_template_directory mentions in roots/lib/scripts.php but that has no effect at all.

What do I need to do to make the styles and js files in the child theme folder load properly?? Please help, as now I can't create the child theme at all, making roots useless...

[update] I moved my wordpress install up a level ( localhost/site2 in stead of localhost/wordpress/site2) and now everything seems to be working properly. Still, this bug needs fixing![/update]

bsides commented 11 years ago

Sorry, this post really looks the same as my issue 585. Hope it will be fixed soon without hacks. Farewell!

brianfeister commented 11 years ago

FYI - every time I do a new site with Roots, I hope that this issue has been fixed with a version bump since my previous use of Roots. As of version 6.1.0 (downloaded yesterday - 10/30/12) I still get broken permalinks with my local instance which I always have nested several folders deep.

retlehs commented 11 years ago

yes, we know it'd be nice to have this bug fixed.

your options right now are:

  1. implement the temp fix (quick/easy/painless)
  2. disable clean URLs
  3. don't use more than 1 subdirectory
Foxaii commented 11 years ago

@brianfeister Can you try using get_theme_root_uri() . '/' . get_template() instead of get_template_directory_uri() and let me know if that works please.

ghost commented 11 years ago

hi! just remove get_template_directory_uri() . in .......\lib\scripts.php

ohneSehnsucht commented 11 years ago

I encountered this problem with the css and js file paths coming up wrong in the head section (with part of the path being duplicated).

Setup: wordpress 3.5, roots latest (jan 2013), mac os 10.6, using localhost and Sites, roots theme therefore several subfolders down.

The issue was finally resolved by using brucedav's tip: "...I have resolved the issue by replacing all references to get_template_directory_uri() in scripts.php with WP_CONTENT_URL and including /themes/roots to the path that follows..."

I had also already done all the recommended alterations to the .htaccess file.