-1

I have a large script hard-coded in the bottom of my footer.

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>

I want to put it in my functions.php file and just call it at this point if that is possible/will it work.

user3550879
  • 3,389
  • 6
  • 33
  • 62
  • 3
    Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Epodax Jul 15 '16 at 10:47
  • why you are not create one .js file and will include it here – Dhaval Bhavsar Jul 15 '16 at 10:48
  • I have other .js files and functions files etc. I just want to put it in one of those and figured functions.php is the best – user3550879 Jul 15 '16 at 10:53

1 Answers1

0

Please make a separate js file for it and include it in that html page. In this way , your code will be well maintainable and it can be cached by browser resulting in significant performance improvement.

Lakin Mohapatra
  • 1,097
  • 11
  • 22
  • how do I bring it into the page? I have got the php to wor but all my scripts are hard-coded – user3550879 Jul 15 '16 at 10:59
  • 1. Create a js file and copy all hardcoded js codes into it . Note : dont use – Lakin Mohapatra Jul 15 '16 at 11:14
  • If you have one existing js file , the you can include the js code there . Its not good to include it in php page. – Lakin Mohapatra Jul 15 '16 at 12:43