3

I'm trying to make the move to Sage 9 as a starter template, however when I try use get_template_directory_uri() I get a return from within the /resources directory.

Unfortunately the assets I want are in the dist folder, a sibling of resources (as per Sage 9's documentation)

I'm using @asset which works fine inside a blade, but I cannot access that from within another php file.

In Sage 8 and vanilla WordPress this was always the method I used to access my theme URI.

Is there something I'm doing wrong with this?

Thanks

Drew
  • 83
  • 1
  • 5

2 Answers2

3

You can use asset() helper equivalent in other WP PHP files like so:

\App\asset_path('your_folder/file_from_dist.ext');
Mtxz
  • 3,749
  • 15
  • 29
2

I think you can use get_theme_file_uri() and that will give you the URL to the theme folder.

In my demo get_template_directory_uri() returns http://sage.test/wp-content/themes/sage-demo while get_template_directory_uri() returns http://sage.test/wp-content/themes/sage-demo/resources.

Andrew Shell
  • 810
  • 1
  • 8
  • 15
  • Thanks for your reply! That's actually exactly what I've done, but it feels more of a workaround than the solution. It seems strange that they would intentionally change how a default, highly used, WordPress function works :-/ – Drew Aug 29 '18 at 16:09