(I am following this Book "Bootstrap Site Blueprint" and I am now in chapter 3. It introduces the use of Roots as a starting theme for Wordpress. )
I am creating custom theme for Wordpress, and I encountered a problem when I try to connect to my own stylesheet by modifying the scripts.php.
Here's my file structure:
|bootstrappin-theme
|assets
|css
|main.css
|lib
|scripts.php
And here's the related code in scripts.php
if (WP_ENV === 'development') {
$assets = array(
'css' => '/assets/css/main.css',
'js' => '/assets/js/scripts.js',
'modernizr' => '/assets/vendor/modernizr/modernizr.js',
'jquery' => '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js'
);
}
else {
$get_assets = file_get_contents(get_template_directory() . '/assets/manifest.json');
$assets = json_decode($get_assets, true);
$assets = array(
'css' => '/assets/css/main.min.css?' . $assets['assets/css/main.min.css']['hash'],
'js' => '/assets/js/scripts.min.js?' . $assets['assets/js/scripts.min.js']['hash'],
'modernizr' => '/assets/js/vendor/modernizr.min.js',
'jquery' => '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'
);
}
wp_enqueue_style('roots_css', get_template_directory_uri() . $assets['css'], false, null);
Then I checked the browser, there's a 404 error requesting "main.css" with the url read from request log:"127.0.0.1/wordpress/assets/css"
So I changed the path for css from '/assets/css/main.css' to
'/wp-content/themes/bootstrappin-theme/assets/css/main.css'.
It now looks like:
if (WP_ENV === 'development') {
$assets = array(
'css' => '/wp-content/themes/bootstrappin-theme/assets/css/main.css',
...
wp_enqueue_style('roots_css', get_template_directory_uri() . $assets['css'], false, null);
However, it's still 404 error and weirdly, when I checked the path in browser, The path to main.css is still
main.css
127.0.0.1/wordpress/assets/css
The tricky part I found is that, the path output will never reach my bootstrappin-theme folder and its
behaviour is weird.
Examlpe 1
So for example, if I change the code in scripts.php to
/wp-content/themes/bootstrappin-theme-example/assets/css/main.css
the path output in browser will ignore everything before /wp-content/themes/bootstrappin-theme-example and it will be like this:
127.0.0.1/wordpress/assets/css
Yes, exactly like before.
Example 2
If I change the code to
/wp-content/themes-example/bootstrappin-theme/assets/css/main.css
The output will be:
127.0.0.1/wordpress/wp-content/themes-example/bootstrappin-theme/assets/css/main.css
Thank you in advance.