Can I change get_template_directory_uri()?

This is sort of a follow up to Can I put my WordPress theme files in another folder?

I found that following

...\wp-content\themes\MyTheme
  - \dist
  - \lib
  - \src
  - \wp - All my WordPress files like index.php, style.css, functions.php, etc.
  - .gitignore
  - README.md
  - many other non-Wordpress files

Generally works in better grouping my WordPress files into its own folder. However, it also changes get_template_directory_uri() to now point to ...\themes\MyTheme\wp which means somewhere in my header.php I am calling

<script src="https://wordpress.stackexchange.com/questions/211811/<?php echo get_template_directory_uri(); ?>/dist/bundle.js"></script>

I’d like for get_template_directory_uri() to point to ...\themes\MyTheme so I can avoid having to use the /../ thing in the path.

4 Answers
4

If you look at the function in source, you’ll see the template_directory_uri hook you can filter to modify output.

return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri );

Leave a Comment