daily pastebin goal
25%
SHARE
TWEET

WordPress - Add JavaScript to a page

lorro Jun 10th, 2015 (edited) 240 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // add a JavaScript to a page
  3.   // code goes in functions.php for your child theme
  4.   add_action( 'wp_enqueue_scripts', 'add_my_script' );
  5.   function add_my_script() {
  6.     $my_page_id = 57; // set to the required page
  7.     if ($my_page_id == get_the_id() ) {
  8.       wp_enqueue_script( 'my-js', '/wp-content/uploads/my_script.js', array(), "1", true);
  9.     }
  10.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top