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="<?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.
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="<?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
Reset to default 4If 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
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.
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 Commented Dec 15, 2015 at 1:11