• Resolved nipoma

    (@nipoma)


    So I bought a custom theme, and the devs over there have absolutely no clue what they did apparantly. I’ve read the wp_enqueue part in the codex. But their way of doing this is completely new to me. I want to make sure all .js gets loaded in the footer. But I’m unsure how to do it in this case:

    N.B.: yes I know, too much .js, this theme sucks but it’ll have to do for now.

    function aitEnqueueScriptsAndStyles()
    {
    	// just shortcuts
    	$s = THEME_CSS_URL;
    	$j = THEME_JS_URL;
    
    	aitAddStyles(array(
    		'ait-jquery-prettyPhoto'  => array('file' => "$s/prettyPhoto.css"),
    		'ait-jquery-fancybox'     => array('file' => "$s/fancybox/jquery.fancybox-1.3.4.css"),
    		'ait-jquery-hover-zoom'   => array('file' => "$s/hoverZoom.css"),
    		'ait-jquery-fancycheckbox'=> array('file' => "$s/jquery.fancycheckbox.min.css"),
    		'jquery-ui-css'           => array('file' => "$s/jquery-ui-1.10.1.custom.min.css"),
    	));
    
    	aitAddScripts(array(
    		'jquery-ui-tabs'              => true,
    		'jquery-ui-accordion'         => true,
    		'jquery-ui-autocomplete'      => true,
    		'jquery-ui-slider'            => true,
    		'ait-jquery-fancycheckbox'    => array('file' => "$j/libs/jquery.fancycheckbox.min.js", 'deps' => array('jquery')),
    		'ait-jquery-html5placeholder' => array('file' => "$j/libs/jquery.html5-placeholder-shim.js", 'deps' => array('jquery')),
    		'ait-googlemaps-api'          => array('file' => 'http://maps.google.com/maps/api/js?sensor=false&language=en', 'deps' => array('jquery')),
    		'ait-jquery-gmap3-label'      => array('file' => "$j/libs/gmap3.infobox.js", 'deps' => array('jquery')),
    		'ait-jquery-gmap3'            => array('file' => "$j/libs/gmap3.min.js", 'deps' => array('jquery')),
    		'ait-jquery-infieldlabel'     => array('file' => "$j/libs/jquery.infieldlabel.js", 'deps' => array('jquery')),
    		'ait-jquery-prettyPhoto'      => array('file' => "$j/libs/jquery.prettyPhoto.js", 'deps' => array('jquery')),
    		'ait-jquery-fancybox'         => array('file' => "$j/libs/jquery.fancybox-1.3.4.js", 'deps' => array('jquery')),
    		'ait-jquery-easing'           => array('file' => "$j/libs/jquery.easing-1.3.min.js", 'deps' => array('jquery')),
    		'ait-jquery-nicescroll'       => array('file' => "$j/libs/jquery.nicescroll.min.js", 'deps' => array('jquery')),
    		'ait-jquery-quicksand'        => array('file' => "$j/libs/jquery.quicksand.js", 'deps' => array('jquery')),
    		'ait-jquery-hover-zoom'       => array('file' => "$j/libs/hover.zoom.js", 'deps' => array('jquery')),
    		'ait-jquery-finished-typing'  => array('file' => "$j/libs/jquery.finishedTyping.js", 'deps' => array('jquery')),
    		'ait-spin-ajax-loader'        => array('file' => "$j/libs/spin.min.js"),
    		'ait-modernizr-touch'         => array('file' => "$j/libs/modernizr.touch.js"),
    		'ait-gridgallery'             => array('file' => "$j/gridgallery.js", 'deps' => array('jquery')),
    		'ait-rating'                  => array('file' => "$j/rating.js", 'deps' => array('jquery')),
    		'ait-script'                  => array('file' => "$j/script.js", 'deps' => array('jquery')),
    	));
    	wp_localize_script( 'ait-script', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'ajaxnonce' => wp_create_nonce('ajax-nonce') ) );
    }
    add_action('wp_enqueue_scripts', 'aitEnqueueScriptsAndStyles');

    So I changed that crap to this (I’ll just show one rule instead of all the code):

    'ait-script' => array('file' => "$j/script.js", 'deps' => array('jquery'), '', true),

    The script isn’t loaded in the footer yet. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nipoma

    (@nipoma)

    Decided to ditch the entire theme. Problem solved.

    For future, you want to do wp_enqueue_script and wp_enqueue_style,
    and use the wp_footer hook to load them in the footer.

    Example:

    function load_js_in_footer() {
        wp_enqueue_script( 'test.js' , get_template_directory_uri() . '/js/test.js', array(), '1.0.0', true );
    }
    add_action( 'wp_footer' , 'load_js_in_footer' );

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

The topic ‘wp_enqueue use in_footer’ is closed to new replies.