Glossary E Enqueue


The best way to load custom scripts (JavaScript) and styles (CSS) into WordPress is to use the wp_enqueue_scripts hook. Rather than merely hard-coding scripts and styles into your Child Theme it is best to load them into this dynamic system so you can take precise control over where they load on your site. Not all scripts and styles are needed on every page, and it can be beneficial to your site’s overall speed to use PHP logic to add and remove them when needed. Using MD’s Scripts Manager can make this process even easier.

Code example:

function md_child_enqueue() {
    wp_enqueue_script( 'md-child-script-name' . '' );
    wp_enqueue_style( 'md-child-style-name' . '' );
add_action( 'wp_enqueue_scripts', 'md_child_enqueue' );

Learn more from the WordPress Developer Guide.