do_action( 'wp_enqueue_scripts' )

Fires when scripts and styles are enqueued.

Description Description

Source Source

File: wp-includes/script-loader.php

View on Trac

Top ↑

Changelog Changelog

Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes

    Basic Example

     * Proper way to enqueue scripts and styles.
    function wpdocs_theme_name_scripts() {
        wp_enqueue_style( 'style-name', get_stylesheet_uri() );
        wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
  2. Skip to note 3 content

    This actions passes an argument $hook that is handy when for example to prevent the script from loading on certain pages;

    function wpdocs_enqueue_scripts( $hook ) {
    	// Load only in add new post page
    	if ( is_admin() && 'post-new.php' !== $hook ) {
    	// rest of your code here..
    add_action( 'wp_enqueue_scripts', 'wpdocs_enqueue_scripts' );

You must log in before being able to contribute a note or feedback.