Skip to content

Instantly share code, notes, and snippets.

@SErr0r
Last active March 31, 2018 08:57
Show Gist options
  • Save SErr0r/e99ab93ff7a138c9549f3ebdef4da783 to your computer and use it in GitHub Desktop.
Save SErr0r/e99ab93ff7a138c9549f3ebdef4da783 to your computer and use it in GitHub Desktop.
Register WordPress Scripts
<?php
// Add custom JS script to WordPress admin.
function custom_scripts() {
wp_register_script( 'my-admin-script', 'http://example.com/custom.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'my-admin-script' );
}
// Hook into the 'admin_enqueue_scripts' action
add_action( 'admin_enqueue_scripts', 'custom_scripts' );
<?php
// Add custom JS script to WordPress login.
function custom_scripts() {
wp_register_script( 'my-login-script', 'http://example.com/custom.js', array( 'jquery' ), '1.0', false );
wp_enqueue_script( 'my-login-script' );
}
// Hook into the 'login_enqueue_scripts' action
add_action( 'login_enqueue_scripts', 'custom_scripts' );
<?php
// Register Scripts – jQuery, jQuery Migrate, Bootstrap & Custom Script
function custom_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_register_style( 'bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css', array(), '4.0.0', 'all' );
wp_enqueue_style( 'bootstrap' );
wp_register_script( 'popper', '//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js', array( 'jquery' ), '1.12.9', true );
wp_enqueue_script( 'popper' );
wp_register_script( 'bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.0.0', true );
wp_enqueue_script( 'bootstrap' );
wp_register_script( 'script', get_template_directory_uri() .'/assets/js/script.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'script' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment