0

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.com/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.com/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.

-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' );
  • It's unclear what this code does, where to add this code, or how it solves the original question. Could you edit your answer using the edit link above and add an explanation on what this code does please? The idea is that answers should educational and informational, code only answers may be poorly received by the community. – Howdy_McGee Jan 4 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.