Add Javascript To Specific WordPress Pages Using Functions.php




Grab Your Free 17-Point WordPress Pre-Launch PDF Checklist: http://vid.io/xqRL
Add Javascript To Specific WordPress Pages https://youtu.be/Fw6VDOZYqrM

Link to blog post with code: https://wplearninglab.com/add-javascript-specific-wordpress-pages/

Link to Conditional Tags in WordPress codex: https://codex.wordpress.org/Conditional_Tags

If you want to add JavaScript to a specific page in WordPress this is how you do it without using a plugin. You do have edit the functions.php file, so do that carefully. Backup your existing functions file if you need to. Then just use the code from the blog post to add JavaScript to any page on your WordPress site.

Stop brute force attacks before they happen with this workshop: https://wplearninglab.com/brute-force-eliminator-workshop

Grab your free 17-Point WordPress Pre-Launch PDF Checklist: http://vid.io/xqRL

Download your exclusive 10-Point WP Security Checklist: http://bit.ly/10point-wordpress-hardening-checklist

Subscribe to this awesome channel here: http://www.youtube.com/subscription_center?add_user=wplearninglab

Original source


32 responses to “Add Javascript To Specific WordPress Pages Using Functions.php”

  1. Thanks so much for the detailed explanation, quick question: Can you add multiple scripts to the same header, e.g. AdSense and Google analytics? and how do you separate them to be sure they are well laid out for google?

  2. Sorry, I have redone my comment 馃檪 Thank you for your help, and I have got it all working well. But, i have an issue with wordpress removing my code after changing screens to the visual. I used your method in the video for the specific page, but any ideas how to stop making wordpress change my code when flicking to the visual? here is the JS i used instead of I am here alert: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_copy_clipboard

  3. I pasted the code below into my website's template just before the </BODY> tag but still not working. Please help

    var pubID = '45215CL40786';
    (function(d, t) {

    var s = document.createElement('script');s.type = 'text/javascript';

    s.async = true;s.src = (document.location.protocol == 'https:' ? 'https://cdn0.cuelinks.com/js/&#39; : 'http://cdn0.cuelinks.com/js/&#39馃槈 + 'cuelinksv1.js';

    document.getElementsByTagName('body')[0].appendChild(s);

    }());

  4. //Script code for Copy to ClipBoard
    function copyDivToClipboard() {
    var range = document.getSelection().getRangeAt(0);
    range.selectNode(document.getElementById("a"));
    window.getSelection().addRange(range);
    document.execCommand("copy")
    }
    add_action( 'wp_enqueue_scripts', 'copyDivToClipboard' );

    It is showing me "syntax error, unexpected T_VAR"

  5. This is exactly what I want to do. Run a javascript on one specific page. I did as instructed. To test I first only created one java file with the alert command you showed. The alert does not show up but I can see in the source that the java file is loaded. I am running WordPress. Is there any other setting I should change to enable the execution of the java file? (The alert should show up here: http://science-network.tv/signs-test-mcnemars-test/ and the java file is currently pairwise_test.js)

Leave a Reply