admin管理员组文章数量:1122832
There're quite a lot of functions, and so, does my theme, it all gets a little cluttered even with all the comments. Additionally, every time the theme is updated, the new functions.php file would replace the current one.
So, it becomes a pain.
Hence, I thought, would it be possible to have a 2nd/3rd functions.php file? Using PHP include or require function. That way, I can categorise the functions and they won't be affected on theme update.
So,
<?php include 'functions_1.php' ?>
Thanks,
There're quite a lot of functions, and so, does my theme, it all gets a little cluttered even with all the comments. Additionally, every time the theme is updated, the new functions.php file would replace the current one.
So, it becomes a pain.
Hence, I thought, would it be possible to have a 2nd/3rd functions.php file? Using PHP include or require function. That way, I can categorise the functions and they won't be affected on theme update.
So,
<?php include 'functions_1.php' ?>
Thanks,
Share Improve this question asked Feb 10, 2018 at 23:54 Haneef Ibn AhmadHaneef Ibn Ahmad 113 bronze badges 4- 1 Are you using a child theme? – Milo Commented Feb 11, 2018 at 0:26
- @Milo No child theme used – Haneef Ibn Ahmad Commented Feb 11, 2018 at 0:28
- 1 If you want to add functionality to a theme modifying it in any way (even just to include other files) is not the way to do it. This is what child themes are for. – Jacob Peattie Commented Feb 11, 2018 at 2:18
- 1 yes, you can include other files. it's just like any other php file. – inarilo Commented Feb 11, 2018 at 4:51
1 Answer
Reset to default 3You can get rid of the theme update situation by using a child theme. Your child theme will work as an extension of the parent theme that you update often. You can learn more about child theme from here.
But if you don't wanna use child theme then yes, you can add as many additional functions file as you want. A regular include
or require
will just work fine. You can include file using a relative path or you can use get_template_directory()
function for an absolute path. For instance
include get_template_directory() . '/inc/functions-1.php'; // if it's inside inc directory
include get_template_directory() . '/functions-1.php'; // Or if it's not inside any directory
本文标签: includeCan I have an additional functionsphp file in Wordpress
版权声明:本文标题:include - Can I have an additional functions.php file in Wordpress? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736285121a1927393.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论