Answers for "enqueue js in wordpress"

PHP
8

enqueue wordpress

function wpdocs_theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() ); /* enqueues style.css */
    /* if you want to enqueue other styles use: */
    /* wp_enqueue_style( 'style-name', get_template_directory_uri() . '/css/your-style-name.css' ); */
    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' );
Posted by: Guest on May-25-2020
0

wordpress enqueue script

function add_theme_scripts() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );
 
  wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), '1.1', 'all');
 
  wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);
 
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
      wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
Posted by: Guest on November-15-2020
0

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' );
Posted by: Guest on August-07-2021

Browse Popular Code Answers by Language