Jump to content

Archived

This topic is now archived and is closed to further replies.

camaran

the best mode to add script

Recommended Posts

camaran

what's the best mode for add javascript in DMS child themes? using wp_enqueu_script function?

Share this post


Link to post
Share on other sites
Danny

Hi,

 

You can either add your JS files via DMS Toolbar > Custom > Custom Scripts or use the enqueue via the child themes functions.php file. The choice is to up to, the Custom Scripts method is the simplest.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
camaran

but enqueue in functions.php is better for performance?

Share this post


Link to post
Share on other sites
Erwan

Hi camaran,

As for me, I use the standard Wordpress process with DMS, with the best practice (though not mandatory) i.e. registering before enqueuing.

The only specific stuff I noticed is: with DMS, in order to you load scripts in footer, you must set to true optional $in_footer parameter, which was not the case in Framework if I remember well.

Hence, in my child theme functions.php, I have for instance what follows. Let me know if you have an issue!

 

add_action( 'wp_enqueue_scripts', 'load_my_own_scripts' );

function load_my_own_scripts() {
        
        // This one in header, with a jQuery dependency, and versioned
        wp_register_script( 'my-first-script', get_stylesheet_directory_uri() . '/js/myfirstscript.js', array('jquery'), '1.0', false );
        
        // This one in footer, with no dependency, and not versioned
        wp_register_script( 'my-second-script', get_stylesheet_directory_uri() . '/js/mysecondscript.js', '', true );
	
        wp_enqueue_script( 'my-first-script' );
	wp_enqueue_script( 'my-second-script' );
}

Share this post


Link to post
Share on other sites

×