Title: Adding jquery to custom WP theme
Last modified: August 21, 2016

---

# Adding jquery to custom WP theme

 *  [Spiff75](https://wordpress.org/support/users/spiff75/)
 * (@spiff75)
 * [13 years ago](https://wordpress.org/support/topic/adding-jquery-to-custom-wp-theme/)
 * So what do I need to do to get it working?
 * I’m not expert and just improvised the code which should resize image on window
   resize to be 80% of the shorter screen side maintaining ratio:
 *     ```
       $(window).resize(function() {
       	function imgResize()
       	{
   
       		if ($("#post_container img").width() > $("#post_container img").height()){
   
       			$('#post_container img').css({ 'width': '80%', 'height': 'auto' });
       			}
       		else if ($("#post_container img").width() < $("#post_container img").height()){
   
       			$('#post_container img').css({ 'width': 'auto', 'height': '80%' });
       			}
       		else {
       			$('#post_container img').css({ 'width': '80%', 'height': 'auto' });
       			}
   
       	}
   
       })
       ```
   
 * Is that even right?
 * I also have these in my functions.php:
 *     ```
       function my_init_method() {
           if (!is_admin()) {
               wp_deregister_script( 'jquery' );
               wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js');
               wp_enqueue_script( 'jquery' );
           }
       }
   
       add_action('init', 'my_init_method');
   
       function add_my_script() {
       wp_enqueue_script(
           're-size', // name your script so that you can attach other scripts and de-register, etc.
           get_template_directory_uri() . '/js/imageResize.js', // this is the location of your script file
           array('jquery') // this array lists the scripts upon which your script depends
       );
       }
   
       add_action( 'wp_enqueue_scripts', 'add_my_script' );
   
       // smart jquery inclusion
       if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
       function my_jquery_enqueue() {
          wp_deregister_script('jquery');
          wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
          wp_enqueue_script('jquery');
       }
       ```
   
 * Is there something extra or something missing?
 * And then I have this in my header.php in the head tag:
 *     ```
       <?php wp_enqueue_script("jquery"); ?>
       ```
   
 * So whats wrong, too much or missing?

The topic ‘Adding jquery to custom WP theme’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Spiff75](https://wordpress.org/support/users/spiff75/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/adding-jquery-to-custom-wp-theme/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
