New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to move required theme files to theme root folder #3

QWp6t opened this Issue Aug 8, 2017 · 7 comments


None yet
4 participants

QWp6t commented Aug 8, 2017

See: roots/sage#1938


This comment has been minimized.

jkwasniak commented Aug 12, 2017

It would be great if a task to package theme (of using the WordPress installer) with all required dependencies is added so it can be directly invoked using yarn run (example: yarn run build:wordpress-installer-production).


This comment has been minimized.

dmgawel commented Oct 19, 2017

I just made an attempt (successful for now) to move required files to root directory. I'd like to share steps to reproduce this modified setup and issues I've come across. Maybe this will help with development.

Sage setup with required theme files in top-level directory

  1. Move index.php, functions.php, style.css and screenshot.png to theme's root directory.

  2. Move resources/views to root (/views). This is required for Page Templates to work because WordPress is looking for them only one level deeper than style.css is located.

Then, tell Sage where to look for view files. In config/views.php:

     'paths' => [
-        get_theme_file_path().'/resources/views',
-        get_parent_theme_file_path().'/resources/views',
+        get_theme_file_path().'/views',
+        get_parent_theme_file_path().'/views',

Additionally, until roots/sage#1980 is merged, fix template hierarchy in app/helpers.php:

function filter_templates($templates)
                     return [
-                        "{$template}.blade.php",
-                        "{$template}.php",
-                });
+                })
+                ->concat([
+                    "{$template}.blade.php",
+                    "{$template}.php",
+                ]);
  1. In functions.php fix paths to loaded files:

Composer autoloader:

  * Ensure dependencies are loaded
 if (!class_exists('Roots\\Sage\\Container')) {
-    if (!file_exists($composer = __DIR__.'/../vendor/autoload.php')) {
+    if (!file_exists($composer = __DIR__.'/vendor/autoload.php')) {
             __('You must run <code>composer install</code> from the Sage directory.', 'sage'),
             __('Autoloader not found.', 'sage')

Sage required files:

  * Add or remove files to the array as needed. Supports child theme overrides.
 array_map(function ($file) use ($sage_error) {
-    $file = "../app/{$file}.php";
+    $file = "./app/{$file}.php";
     if (!locate_template($file, true, true)) {
         $sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');

Disable filter correcting paths to theme in default Sage setup:

-    'add_filter',
-    ['theme_file_path', 'theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'],
-    array_fill(0, 4, 'dirname')

Paths to config files:

     ->bindIf('config', function () {
         return new Config([
-            'assets' => require dirname(__DIR__).'/config/assets.php',
-            'theme' => require dirname(__DIR__).'/config/theme.php',
-            'view' => require dirname(__DIR__).'/config/view.php',
+            'assets' => require __DIR__.'/config/assets.php',
+            'theme' => require __DIR__.'/config/theme.php',
+            'view' => require __DIR__.'/config/view.php',
     }, true);
  1. Fix paths to controllers and models (if used).

Default directory in soberwp/controller and soberwp/models assume that required files are in resources directory. This might change in future (soberwp/controller#54) but for now in app/setup.php add:

 * Soberwp Models
add_filter('sober/models/path', function () {
    return get_theme_file_path() . '/app/models';

 * Soberwp Controller
add_filter('sober/controller/path', function () {
    return get_theme_file_path() . '/app/controllers';

That's it. Everything should be working now as expected. Hope this helps :-)

@dmgawel dmgawel referenced this issue Oct 19, 2017


Template hierarchy and index.php collision #1979

5 of 6 tasks complete

This comment has been minimized.

MikeiLL commented Jan 1, 2018

@dmgawel Does this fix work at this point? From your EDIT note above I am gathering not.


This comment has been minimized.

dmgawel commented Jan 2, 2018

@MikeiLL I've just updated my previous post. It now contains working solution :-)


This comment has been minimized.

MikeiLL commented Jan 6, 2018

Hey thanks @dmgawel I'm almost there.

However, illuminate/view/FileViewFinder.php is looking for blades in
    [0] => /var/www/html/wp-content/themes/MyTheme/resources/views
    [1] => /var/www/html/wp-content/themes/MyTheme/resources/views

If I copy the views directory back there the theme loads, but that's obviously not the answer.

Is there config somewhere I missed? Asking at Roots Discourse as well. Thanks.


This comment has been minimized.

MikeiLL commented Jan 8, 2018

Found it.

Update config/views.php.

'paths' => [

Remove /resources from the paths.


This comment has been minimized.

dmgawel commented Jan 9, 2018

@MikeiLL thanks! Indeed, I have this change also in my code but forgot to include it. I'm going to edit my post and add it for future reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment