$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - Why my wp_enqueue_script doesnt work on some page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Why my wp_enqueue_script doesnt work on some page?

matteradmin10PV0评论

My wp_enqueue_script from my theme is working on home page and not on other page.

This is my web : .

And here is not working : /

So on home page, all of the wp_enqueue_script that declared on Function.php load all the scripts. but on the other page, just some of the scripts are loaded.

here is my function for wp_enqueue_script:

add_action('wp_enqueue_scripts', 'listingpro_scripts');

function listingpro_scripts() {


    global $listingpro_options;

    wp_enqueue_script('Mapbox', THEME_DIR . '/assets/js/mapbox.js', 'jquery', '', true);
    wp_enqueue_script('Mapbox-leaflet', THEME_DIR . '/assets/js/leaflet.markercluster.js', 'jquery', '', true);

    //wp_enqueue_script('Build', THEME_DIR . '/assets/js/build.min.js', 'jquery', '', true);

    wp_enqueue_script('Chosen',THEME_DIR. '/assets/lib/chosen/chosen.jquery.js', 'jquery', '', true);   

    wp_enqueue_script('popper', THEME_DIR . '/assets/lib/popper/popper.min.js', 'jquery', '', true);

    wp_enqueue_script('tooltip', THEME_DIR . '/assets/lib/popper/tooltip.min.js', 'jquery', '', true);

    wp_enqueue_script('bootstrap', THEME_DIR . '/assets/lib/bootstrap/js/bootstrap.min.js', 'jquery', '', true);

    wp_enqueue_script( 'flickity', THEME_DIR . '/assets/js/flickity.pkgd.min.js');

    wp_enqueue_script('Mmenu', THEME_DIR . '/assets/lib/jquerym.menu/js/jquery.mmenu.min.all.js', 'jquery', '', true);

    wp_enqueue_script('magnific-popup', THEME_DIR . '/assets/lib/Magnific-Popup-master/jquery.magnific-popup.min.js', 'jquery', '', true);

    wp_enqueue_script('select2', THEME_DIR . '/assets/js/select2.full.min.js', 'jquery', '', true); 

    wp_enqueue_script('popup-classie', THEME_DIR . '/assets/lib/popup/js/classie.js', 'jquery', '', true);

    wp_enqueue_script('modalEffects', THEME_DIR. '/assets/lib/popup/js/modalEffects.js', 'jquery', '', true);       
    wp_enqueue_script('2checkout', THEME_DIR. '/assets/js/2co.min.js', 'jquery', '', true); 

    wp_enqueue_script('Owl-Carousel',THEME_DIR. '/assets/js/owl.carousel.min.js', 'jquery', '', true);  

    wp_enqueue_script('promo-ajax-script',THEME_DIR. '/assets/js/tambahan.js', 'jquery', '', true);
    wp_enqueue_script('news-ajax-script',THEME_DIR. '/assets/js/tambahan.js', 'jquery', '', true);
    wp_enqueue_script('jquery-ui',THEME_DIR . '/assets/js/jquery-ui.js', 'jquery', '', true);

    wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    if(class_exists('Redux')){
        $mapAPI = '';
        $mapAPI = $listingpro_options['google_map_api'];
        if(empty($mapAPI)){
            $mapAPI = 'AIzaSyDQIbsz2wFeL42Dp9KaL4o4cJKJu4r8Tvg';
        }
        wp_enqueue_script('mapsjs', ';amp;key='.$mapAPI.'&libraries=places', 'jquery', '', false);   
    }
    if(!is_front_page()){
        wp_enqueue_script('pagination', THEME_DIR . '/assets/js/pagination.js', 'jquery', '', true);
    }
    /* IF ie9 */
        wp_enqueue_script('html5shim', '.js', array(), '1.0.0', true);
        wp_script_add_data( 'html5shim', 'conditional', 'lt IE 9' );

        wp_enqueue_script('nicescroll', THEME_DIR. '/assets/js/jquery.nicescroll.min.js', 'jquery', '', true);
        wp_enqueue_script('chosen-jquery', THEME_DIR . '/assets/js/chosen.jquery.min.js', 'jquery', '', true);
        wp_enqueue_script('jquery-ui',THEME_DIR . '/assets/js/jquery-ui.js', 'jquery', '', true);
    if(is_page_template( 'template-dashboard.php' )){
        wp_enqueue_script('bootstrap-rating', THEME_DIR . '/assets/js/bootstrap-rating.js', 'jquery', '', true);
    }
    wp_enqueue_script('droppin', THEME_DIR. '/assets/js/drop-pin.js', 'jquery', '', true);  
    if(is_singular('listing')){
        wp_enqueue_script('singlemap', THEME_DIR. '/assets/js/singlepostmap.js', 'jquery', '', true);
        wp_enqueue_script('socialshare', THEME_DIR . '/assets/js/social-share.js', 'jquery', '', true);
        wp_enqueue_script('jquery-prettyPhoto', THEME_DIR. '/assets/js/jquery.prettyPhoto.js', 'jquery', '', true);
        wp_enqueue_script('bootstrap-rating', THEME_DIR . '/assets/js/bootstrap-rating.js', 'jquery', '', true);
        wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    }
    /* ==============start add by sajid ============ */
    global $listingpro_options;
    $app_view_home  =   $listingpro_options['app_view_home'];
    $app_view_home  =   url_to_postid( $app_view_home );
    if(is_page( $app_view_home ) || is_tax( 'location' ) || (is_front_page()) || is_tax( 'listing-category' ) || is_tax( 'feature' ) || (
            is_search()
            && isset( $_GET['post_type'] )
            && $_GET['post_type'] == 'listing'
    ) ){
    wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    }
    /* ==============end add by sajid ============ */
    wp_enqueue_script('dyn-location-js', THEME_DIR . '/assets/js/jquery.city-autocomplete.js', 'jquery', '', true);
    //if(is_archive()){
        wp_enqueue_script('bootstrapsliderjs', THEME_DIR . '/assets/lib/bootstrap/js/bootstrap-slider.js', 'jquery', '', true);
    //}


    wp_register_script( 'lp-icons-colors', THEME_DIR. '/assets/js/lp-iconcolor.js' , 'jquery', '', true );
    wp_enqueue_script( 'lp-icons-colors' );

    wp_register_script( 'lp-current-loc', THEME_DIR. '/assets/js/lp-gps.js' , 'jquery', '', true );
    wp_enqueue_script( 'lp-current-loc' );

    wp_enqueue_script('Main', THEME_DIR. '/assets/js/main.js', 'jquery', '', true); 





    if ( is_singular('post') && comments_open() ) wp_enqueue_script( 'comment-reply' );

I already tried disabling plugins but still there is an error that my jquery-ui.js is not loaded.

I wonder why. Im not good at php and wordpress so any help would be appreciated.

My wp_enqueue_script from my theme is working on home page and not on other page.

This is my web : https://welgo.id.

And here is not working : https://welgo.id/listing/rs-bandung-eye-center-bandung/

So on home page, all of the wp_enqueue_script that declared on Function.php load all the scripts. but on the other page, just some of the scripts are loaded.

here is my function for wp_enqueue_script:

add_action('wp_enqueue_scripts', 'listingpro_scripts');

function listingpro_scripts() {


    global $listingpro_options;

    wp_enqueue_script('Mapbox', THEME_DIR . '/assets/js/mapbox.js', 'jquery', '', true);
    wp_enqueue_script('Mapbox-leaflet', THEME_DIR . '/assets/js/leaflet.markercluster.js', 'jquery', '', true);

    //wp_enqueue_script('Build', THEME_DIR . '/assets/js/build.min.js', 'jquery', '', true);

    wp_enqueue_script('Chosen',THEME_DIR. '/assets/lib/chosen/chosen.jquery.js', 'jquery', '', true);   

    wp_enqueue_script('popper', THEME_DIR . '/assets/lib/popper/popper.min.js', 'jquery', '', true);

    wp_enqueue_script('tooltip', THEME_DIR . '/assets/lib/popper/tooltip.min.js', 'jquery', '', true);

    wp_enqueue_script('bootstrap', THEME_DIR . '/assets/lib/bootstrap/js/bootstrap.min.js', 'jquery', '', true);

    wp_enqueue_script( 'flickity', THEME_DIR . '/assets/js/flickity.pkgd.min.js');

    wp_enqueue_script('Mmenu', THEME_DIR . '/assets/lib/jquerym.menu/js/jquery.mmenu.min.all.js', 'jquery', '', true);

    wp_enqueue_script('magnific-popup', THEME_DIR . '/assets/lib/Magnific-Popup-master/jquery.magnific-popup.min.js', 'jquery', '', true);

    wp_enqueue_script('select2', THEME_DIR . '/assets/js/select2.full.min.js', 'jquery', '', true); 

    wp_enqueue_script('popup-classie', THEME_DIR . '/assets/lib/popup/js/classie.js', 'jquery', '', true);

    wp_enqueue_script('modalEffects', THEME_DIR. '/assets/lib/popup/js/modalEffects.js', 'jquery', '', true);       
    wp_enqueue_script('2checkout', THEME_DIR. '/assets/js/2co.min.js', 'jquery', '', true); 

    wp_enqueue_script('Owl-Carousel',THEME_DIR. '/assets/js/owl.carousel.min.js', 'jquery', '', true);  

    wp_enqueue_script('promo-ajax-script',THEME_DIR. '/assets/js/tambahan.js', 'jquery', '', true);
    wp_enqueue_script('news-ajax-script',THEME_DIR. '/assets/js/tambahan.js', 'jquery', '', true);
    wp_enqueue_script('jquery-ui',THEME_DIR . '/assets/js/jquery-ui.js', 'jquery', '', true);

    wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    if(class_exists('Redux')){
        $mapAPI = '';
        $mapAPI = $listingpro_options['google_map_api'];
        if(empty($mapAPI)){
            $mapAPI = 'AIzaSyDQIbsz2wFeL42Dp9KaL4o4cJKJu4r8Tvg';
        }
        wp_enqueue_script('mapsjs', 'https://maps.googleapis/maps/api/js?v=3&key='.$mapAPI.'&libraries=places', 'jquery', '', false);   
    }
    if(!is_front_page()){
        wp_enqueue_script('pagination', THEME_DIR . '/assets/js/pagination.js', 'jquery', '', true);
    }
    /* IF ie9 */
        wp_enqueue_script('html5shim', 'https://html5shim.googlecode/svn/trunk/html5.js', array(), '1.0.0', true);
        wp_script_add_data( 'html5shim', 'conditional', 'lt IE 9' );

        wp_enqueue_script('nicescroll', THEME_DIR. '/assets/js/jquery.nicescroll.min.js', 'jquery', '', true);
        wp_enqueue_script('chosen-jquery', THEME_DIR . '/assets/js/chosen.jquery.min.js', 'jquery', '', true);
        wp_enqueue_script('jquery-ui',THEME_DIR . '/assets/js/jquery-ui.js', 'jquery', '', true);
    if(is_page_template( 'template-dashboard.php' )){
        wp_enqueue_script('bootstrap-rating', THEME_DIR . '/assets/js/bootstrap-rating.js', 'jquery', '', true);
    }
    wp_enqueue_script('droppin', THEME_DIR. '/assets/js/drop-pin.js', 'jquery', '', true);  
    if(is_singular('listing')){
        wp_enqueue_script('singlemap', THEME_DIR. '/assets/js/singlepostmap.js', 'jquery', '', true);
        wp_enqueue_script('socialshare', THEME_DIR . '/assets/js/social-share.js', 'jquery', '', true);
        wp_enqueue_script('jquery-prettyPhoto', THEME_DIR. '/assets/js/jquery.prettyPhoto.js', 'jquery', '', true);
        wp_enqueue_script('bootstrap-rating', THEME_DIR . '/assets/js/bootstrap-rating.js', 'jquery', '', true);
        wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    }
    /* ==============start add by sajid ============ */
    global $listingpro_options;
    $app_view_home  =   $listingpro_options['app_view_home'];
    $app_view_home  =   url_to_postid( $app_view_home );
    if(is_page( $app_view_home ) || is_tax( 'location' ) || (is_front_page()) || is_tax( 'listing-category' ) || is_tax( 'feature' ) || (
            is_search()
            && isset( $_GET['post_type'] )
            && $_GET['post_type'] == 'listing'
    ) ){
    wp_enqueue_script('Slick', THEME_DIR . '/assets/lib/slick/slick.min.js', 'jquery', '', true);
    }
    /* ==============end add by sajid ============ */
    wp_enqueue_script('dyn-location-js', THEME_DIR . '/assets/js/jquery.city-autocomplete.js', 'jquery', '', true);
    //if(is_archive()){
        wp_enqueue_script('bootstrapsliderjs', THEME_DIR . '/assets/lib/bootstrap/js/bootstrap-slider.js', 'jquery', '', true);
    //}


    wp_register_script( 'lp-icons-colors', THEME_DIR. '/assets/js/lp-iconcolor.js' , 'jquery', '', true );
    wp_enqueue_script( 'lp-icons-colors' );

    wp_register_script( 'lp-current-loc', THEME_DIR. '/assets/js/lp-gps.js' , 'jquery', '', true );
    wp_enqueue_script( 'lp-current-loc' );

    wp_enqueue_script('Main', THEME_DIR. '/assets/js/main.js', 'jquery', '', true); 





    if ( is_singular('post') && comments_open() ) wp_enqueue_script( 'comment-reply' );

I already tried disabling plugins but still there is an error that my jquery-ui.js is not loaded.

I wonder why. Im not good at php and wordpress so any help would be appreciated.

Share Improve this question asked Jan 4, 2019 at 15:05 VictorVictor 1
Add a comment  | 

1 Answer 1

Reset to default -2

Hi add this code to your Function.php and jquery-ui.js should be loaded correctly on your website.

// Register Script function custom_scripts() {

    wp_register_script( 'jquery-ui', '/assets/js/jquery-ui.js', false, false, true );
    wp_enqueue_script( 'jquery-ui' );

}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
Post a comment

comment list (0)

  1. No comments so far