最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

directory - Can I change get_template_directory_uri()?

programmeradmin0浏览0评论

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.

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Dec 14, 2015 at 21:41 user1778856user1778856 2551 gold badge3 silver badges5 bronze badges 1
  • 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 Commented Dec 15, 2015 at 1:11
Add a comment  | 

4 Answers 4

Reset to default 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

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.

发布评论

评论列表(0)

  1. 暂无评论