Support » Fixing WordPress » how to put js in function.php

  • Resolved taghaboy

    (@taghaboy)


    Hello,
    I used this code in the footer of my theme, to insert to “Hello World” in the div id=”content”

    <script type="text/javascript">
    	document.getElementById('content').innerHTML = '<span class="copyright">Hello world</span>';
    </script>

    So now, i’d like to put the code in the function.php

    Please how to do that?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi taghaboy,

    What you ask is “possible”, but would require a lot of:

    ”./’ changes

    Which will most likely end in php errors or site wreckage. If you need to add JS, it’s way better to add it either in

    header.php or footer.php theme file.

    Plus, you’ll have examples in these files if it’s done well.

    Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Maybe it’s easier if you use a plugin, https://wordpress.org/plugins/custom-css-js-php/

    Note that you’ll probably only want the JS bit (in the plugin) and not the HTML:

    document.getElementById('content').innerHTML = '<span class="copyright">Hello world</span>';

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to put js in function.php’ is closed to new replies.