Title: Javascript in posts
Last modified: September 11, 2016

---

# Javascript in posts

 *  Resolved [johncannon](https://wordpress.org/support/users/johncannon/)
 * (@johncannon)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/)
 * Hello.
 * I have a website where I inserted some scripts I made, on the front page it works
   just fine, I loaded in <head> </head> this:
 *     ```
       <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
       ```
   
 * and then I pasted my script where I wanted, it works fine.
 * When I want to add the same script intro posts, with text editor, nothing happens.
 * This is my script:
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       <p>	
       <img src="" />
   
       <img src="" />
       </p>	
   
       <p  id="demo" > text at loading page </p>  <br>
   
       <!-- FADESCRIPT START -->
   
       <script>
   
       $('.c1').click(function(){
       $('#demo').fadeOut(0).fadeTo( "fast", 0.01 ).fadeTo( "fast", 0.05 ).fadeTo( "fast", 0.09 ).fadeTo( "fast", 1 ).html('text1');
   
       })
   
       $('.c2').click(function(){
       $('#demo').fadeOut(0).fadeTo( "fast", 0.01 ).fadeTo( "fast", 0.05 ).fadeTo( "fast", 0.09 ).fadeTo( "fast", 1 ).html('text2');
   
       })
   
       </script>
   
       <!-- FADESCRIPT  STOP -->
       ```
   
 * It’s just a script that changes the same paragraph with a different text when
   you click on the image with the same class as the one from function. I am not
   an expert with jquery and I don’t know how to make this work in posts. Also if
   there is any other form so that script be written to minify, please tell me.
   
   I tried the solutions from Codex as well as some plugins (Javascrip in posts,
   Advanced Custom Fields) with no result.
    -  This topic was modified 9 years, 6 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

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

 *  [Maria Daniel Deepak](https://wordpress.org/support/users/mariadanieldeepak/)
 * (@mariadanieldeepak)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8169898)
 * Hello [@johncannon](https://wordpress.org/support/users/johncannon/),
 * WordPress strips tags out of your posts and pages. If you prefer to include it,
   you can use plugins to include scripts. One such plugin is [jQuery in Posts Pages](https://wordpress.org/plugins/jquery-in-posts-pages/)
 * If you prefer to it add it via `functions.php`, then this code should help you.
 *     ```
       // Reference: http://wordpress.stackexchange.com/a/151883/83739
       function wpb_adding_scripts() {
       	wp_enqueue_script( 'my_amazing_script', get_template_directory_uri() . '/removeArrows.js', array('jquery'),'0.1', true );
       } 
       add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
       ```
   
 * And finally use `jQuery` in place of `$` in your js file.
    -  This reply was modified 9 years, 6 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
    -  This reply was modified 9 years, 6 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
 *  Thread Starter [johncannon](https://wordpress.org/support/users/johncannon/)
 * (@johncannon)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8170413)
 * I tried with the jQuery in Posts Pages as well as via functions.php. It just 
   doesn’t work, I don’t know what I am doing wrong. Exactly the same script on 
   homepage works great.
    I have edited functions.php and replaced “my_amazing_script”
   with the URL [http://…etc/filename.js](http://…etc/filename.js) where I pasted
   that script with jQuery instead of $.
    -  This reply was modified 9 years, 6 months ago by [johncannon](https://wordpress.org/support/users/johncannon/).
 *  [Maria Daniel Deepak](https://wordpress.org/support/users/mariadanieldeepak/)
 * (@mariadanieldeepak)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8174276)
 * [@johncannon](https://wordpress.org/support/users/johncannon/),
 * In the following line, `my_amazing_script` is the handle for your script. You
   have replace the `src` param.
 * `wp_enqueue_script( 'my_amazing_script', get_template_directory_uri() . '/removeArrows.
   js', array('jquery'),'0.1', true );`
 * **Code Reference**
 * `wp_enqueue_script( string $handle, string $src = false, array $deps = array(),
   string|bool|null $ver = false, bool $in_footer = false )`
 * Also, once you include it in your `functions.php`, check if the script has been
   included in your page by [viewing the page source](http://www.computerhope.com/issues/ch000746.htm)
   in your browser.
 *  Thread Starter [johncannon](https://wordpress.org/support/users/johncannon/)
 * (@johncannon)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8205745)
 * It works, thanks.
 *  [Maria Daniel Deepak](https://wordpress.org/support/users/mariadanieldeepak/)
 * (@mariadanieldeepak)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8216272)
 * [@johncannon](https://wordpress.org/support/users/johncannon/),
 * Glad my answer helped. 🙂

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

The topic ‘Javascript in posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [Maria Daniel Deepak](https://wordpress.org/support/users/mariadanieldeepak/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/javascript-in-posts-7/#post-8216272)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
