Guest User

Load the WP Image Zoom scripts only on specific pages

a guest
Jan 14th, 2026
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2.  
  3. // Dequeue the WP Image Zoom scripts.
  4. add_action( 'wp_print_scripts', function() {
  5.     wp_dequeue_script( 'image_zoooom' );
  6.     wp_dequeue_script( 'image_zoooom-init' );
  7. }, 100 );
  8.  
  9. // Add the WP Image Zoom scripts only to specific pages or posts.
  10. add_action( 'wp_enqueue_scripts', function() {
  11.  
  12.     // Replace the following line with Conditional Tag which matches your page or pages.
  13.     if ( ! is_single( 'simple-post-with-images' ) ) return;
  14.  
  15.     $in_footer = array( 'in_footer' => false, 'strategy'  => 'defer', 'fetchpriority' => 'low' );
  16.  
  17.     // Load the jquery.image_zoom.js
  18.     wp_register_script( 'image_zoooom-2', IMAGE_ZOOM_URL . 'assets/js/jquery.image_zoom.min.js', array( 'jquery' ), IMAGE_ZOOM_VERSION, $in_footer );
  19.     wp_enqueue_script( 'image_zoooom-2' );
  20.  
  21.     // Load the image_zoom-init.js
  22.     wp_register_script( 'image_zoooom-init-2', IMAGE_ZOOM_URL . 'assets/js/image_zoom-init.js', array( 'jquery' ), IMAGE_ZOOM_VERSION, $in_footer );
  23.     wp_localize_script( 'image_zoooom-init-2', 'IZ', ImageZoooom::get_localize_vars() );
  24.     wp_enqueue_script( 'image_zoooom-init-2' );
  25. }, 100 );
  26.  
Advertisement
Add Comment
Please, Sign In to add comment