Title: how to use javascript on wordpress
Last modified: August 30, 2016

---

# how to use javascript on wordpress

 *  [satishdevnani](https://wordpress.org/support/users/satishdevnani/)
 * (@satishdevnani)
 * [11 years ago](https://wordpress.org/support/topic/how-to-use-javascript-on-wordpress/)
 * hello there i want people to share my content to facebook and then they have 
   access to the submit button
 * this is my script it works fine in html or the w3schools testmode
 * but its not working in wordpress
 * this is the whole code i wrote in text mode of a page
 * <!DOCTYPE html>
    <html> <body>
 * <div id=”results”>
    <p>Download content is locked! Please share it & unlock the
   content</p> <center> <img onclick=”shareOnFB();” style=”cursor:pointer” src=”
   [https://d1wofkmqsniyp0.cloudfront.net/public/v2.0/imgs/fbshare.png”&gt](https://d1wofkmqsniyp0.cloudfront.net/public/v2.0/imgs/fbshare.png”&gt);
   </center> </div>
 * <script type=”text/javascript”>
    function shareOnFB() { var e = { method: “feed”,
   link: “[http://w3lessons.info&#8221](http://w3lessons.info&#8221);, picture: “
   [http://w3lessons.info/logo_large.png&#8221](http://w3lessons.info/logo_large.png&#8221);,
   name: “W3lessons – PHP, MYSQL, HTML5, CSS3, jQuery, Ajax, Facebook Style Scripts”,
   caption: ‘w3lessons.info’, description: “w3lessons.info is a programming blog
   maintained by Karthikeyan K. Tutorials focused on Programming, Jquery, Ajax, 
   PHP,HTML5, CSS3, Web Design and MySQL” }; FB.ui(e, function(t) { if (t[“post_id”]){//
   your download content goes here // Do something there var secret_data = “<h2 
   class=\”stitle1\”>Thank you!</h2><h2 class=\”stitle2\”>Please use the below link
   to download</h2><p class=\”d_link\”>[https://app.box.com/s/j23e7gxuug2ml54m09d4](https://app.box.com/s/j23e7gxuug2ml54m09d4)
   </p>”; jQuery(“#results”).html(secret_data); } }) }
 * </script>
 * <div id=”fb-root”></div>
 * <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0]; if(
   d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = “//
   connect.facebook.net/en_US/sdk.js#xfbml=1&appId=843374912383596&version=v2.0”;
   fjs.parentNode.insertBefore(js, fjs); }(document, ‘script’, ‘facebook-jssdk’));
   </script>
 * </body>
    </html>
 * any help would be appreciated please please please help

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [11 years ago](https://wordpress.org/support/topic/how-to-use-javascript-on-wordpress/#post-6214744)
 * I don’t think people are going to help from that code. If you linked to the Webpage
   with the problem then that will be much more appealing.
 *  anonymized-13749270
 * (@anonymized-13749270)
 * [11 years ago](https://wordpress.org/support/topic/how-to-use-javascript-on-wordpress/#post-6214755)
 * Did you place this entire bloc of code in the post editor text mode? that wouldn’t
   help, actually setting up a [custom template](https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post)
   would help, OR enqueueing that JS when the user is viewing that post or page 
   you are working on, something like:
 *     ```
       add_action('wp_head', 'enqueue_my_js');
   
       function enqueue_my_js() {
       	if( is_page( array( 1 ) ) ) {
       		?>
       		<script>
       		Js goes here
       		</script>
       		<?php
       	}
       }
       ```
   
 * To be added in the end of your functions.php file, make sure you add the post/
   page ID in the 4th line instead of 1 ( e.g `is_page( array( 15 ) )` )
 * Let us know how it goes.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘how to use javascript on wordpress’ is closed to new replies.

## Tags

 * [force](https://wordpress.org/support/topic-tag/force/)
 * [html](https://wordpress.org/support/topic-tag/html/)
 * [java](https://wordpress.org/support/topic-tag/java/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [onclick](https://wordpress.org/support/topic-tag/onclick/)
 * [submit](https://wordpress.org/support/topic-tag/submit/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: anonymized-13749270
 * Last activity: [11 years ago](https://wordpress.org/support/topic/how-to-use-javascript-on-wordpress/#post-6214755)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
