如何将脚本放入 functions.php 并调用
How to put script into functions.php and called in
我的页脚底部有一个硬编码的大脚本。
html (footer.php)
<script>
jQuery(document).ready(function($){
// anchor scrolling /
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
...
</script>
</body>
</html>
我想把它放在我的 functions.php 文件中,如果 possible/will 有效,就在此时调用它。
请为它创建一个单独的 js 文件并将其包含在 html 页面中。
这样,您的代码将具有良好的可维护性,并且可以被浏览器缓存,从而显着提高性能。
我的页脚底部有一个硬编码的大脚本。
html (footer.php)
<script>
jQuery(document).ready(function($){
// anchor scrolling /
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
...
</script>
</body>
</html>
我想把它放在我的 functions.php 文件中,如果 possible/will 有效,就在此时调用它。
请为它创建一个单独的 js 文件并将其包含在 html 页面中。 这样,您的代码将具有良好的可维护性,并且可以被浏览器缓存,从而显着提高性能。