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

I found that following

  - \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="<?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.

  • You can write a custom fucntion to pointing your custom directory as theme uri. And than you can make it work by using this action filter template_directory_uri. Also one more suggestion I guess it similar to child theme. So check some informations for child theme creations. Read it from official codec page.
    – Kvvaradha
    Dec 15, 2015 at 1:11

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 );

I'd like to contribute a more detailed answer as I found figuring out 'add_filter()' was quite frustrating.

In order to edit the hook for get_template_directory_uri(), you need to add filter as

add_filter('template_directory_uri', 'yourFunction', 10, 2);

where function is the function you are calling to edit the string, as such:

function yourFunction($string) {
    //Modify the string here
    return $string;

Hope this helps anyone who stumbles across this question in the future!


well you could probably create a variable at the start of your header.php and assign its value string as your desired path....

<?php $dir = your_path_here ?>

theoretically this should work :) best not to change wordpress stuff as it might be used somewhere else

  • perhaps I am just looking for a method to get to ...\themes\MyTheme. Something besides hardcoding or using get_template_directory_uri() with /../ Dec 14, 2015 at 22:03

I was searching for this when doing a migration to a site with another domain name. I fixed this by searching the database. These values are set in the wp_options table of your database. In my case, rows with option_name equal to siteurl and home. I updated the values and everything now works as expected.

  • What is wrong about this answer that it merits a downvote?
    – zundi
    Jun 12, 2019 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.