Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress enqueue scripts and styles

/**
 * 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' );
Comment

how to add js to wordpress with wp_enqueue_scripts

function ti_custom_javascript() {
wp_enqueue_script( 'example-script', get_template_directory_uri() . '/js/examplescript.js');
}
add_action('wp_enqueue_scripts', 'ti_custom_javascript');
Comment

wordpress get list of enqueued scripts and styles

function inspect_scripts() {
    global $wp_scripts;
    print_r($wp_scripts->queue);
}
add_action( 'wp_print_scripts', 'inspect_scripts' );

function inspect_styles() {
    global $wp_styles;
    print_r($wp_styles->queue);
}
add_action( 'wp_print_styles', 'inspect_styles' );
Comment

Enqueue WordPress Scripts and Styles

<?php
/* Enqueue Wordpress Scripts and Styles
-------------------------------------------------- */

function wp_enqueue_scripts_styles() {
    // Javascript - Register Scripts
    wp_register_script( 'bootstrap-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ), '3.2', true ); // -- From Parent Theme
    wp_register_script( 'documents-script', get_stylesheet_directory_uri() . '/bootstrap/docs/docs.min.js', array( 'bootstrap-script' ), '3.2', true ); // -- From Child Theme
    wp_register_script( 'bootlint-script', 'http://maxcdn.bootstrapcdn.com/bootlint/0.3.0/bootlint.min.js', array( 'angularjs-bootstrap-script' ), '0.3.0', true ); // -- From an External URL

    // Javascript - Enqueue Scripts
    wp_enqueue_script( 'bootstrap-script' );
    wp_enqueue_script( 'documents-script' );

    // Stylesheet - Register Styles
    wp_register_style( 'bootstrap-style', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css', '3.2', true ); // -- From Parent Theme
    wp_register_style( 'documents-style', get_stylesheet_directory_uri() . '/bootstrap/docs/docs.min.css', '3.2', true ); // -- From Child Theme
    wp_register_style( 'external-style', 'http://www.example.com/stylesheet.css', '0.0', true ); // -- From an External URL
    
    // Stylesheet - Enqueue Styles
    wp_enqueue_style( 'bootstrap-style' );
    wp_enqueue_style( 'documents-style' );
    
    // Conditional Statement to enqueue Scripts/Styles on specific page templates
    if ( is_page_template( 'page-template.php' ) ) {
      wp_enqueue_script( 'bootlint-script' );
      wp_enqueue_style( 'external-style' );
    }
}

add_action( 'wp_enqueue_scripts', 'wp_enqueue_scripts_styles' );
Comment

wordpress enqueue script on page

function my_enqueue_stuff() {
  if ( is_page( 'landing-page-template-one' ) ) {
    /** Call landing-page-template-one enqueue */
  } else {
    /** Call regular enqueue */
  }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
Comment

enqueue styles and scripts in wordpress

enqueue
Comment

PREVIOUS NEXT
Code Example
Php :: laravel attach once 
Php :: how to on debugger in wordpress 
Php :: PHP Display Posts by Category in WordPress 
Php :: share wordpress post on whatsapp without plugin 
Php :: display image from mysqli database 
Php :: get data of url php 
Php :: Diferencia entre dias PHP 
Php :: how to add page link in laravel 
Php :: get server ip php 
Php :: drupal 8 user_load 
Php :: root composer.json requires php ^7.3 but your php version (8.0.3) does not satisfy that requirement. 
Php :: implode example in php 
Php :: php array to array collection 
Php :: laravel update all relations 
Php :: wp php get product item attributes name 
Php :: how laravel return the old value 
Php :: laravel blade conditional class 
Php :: laravel check if email is verified 
Php :: php string interpolation 
Php :: php array pop by value 
Php :: what does defined di in php 
Php :: update image in database using php 
Php :: function passing multiple arguments using 3 dots php 
Php :: php post variables to another page with submit button php 
Php :: laravel migrations generator laravel 
Php :: php insert array into mysql 
Php :: laravel start que listener 
Php :: toggle between login and logout buttons php 
Php :: ci constructor 
Php :: substract two datetime and get the different hours and minutes php 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =