Skip to content

Instantly share code, notes, and snippets.

@atomjoy
Last active September 17, 2024 15:59
Show Gist options
  • Save atomjoy/9fdc27277e573804edc8bc86336f520d to your computer and use it in GitHub Desktop.
Save atomjoy/9fdc27277e573804edc8bc86336f520d to your computer and use it in GitHub Desktop.
Load scripts and style with do_action hooks in Wordpress.
<?php
// Disable auto updates
add_filter('auto_update_plugin', '__return_false');
add_filter('auto_update_theme', '__return_false');
function load_css() {
// Load bootstrap css
wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap/bootstrap.min.css', [], false, 'all');
wp_enqueue_style('bootstrap');
// Load template css
wp_register_style('main', get_template_directory_uri() . '/css/main.css', [], false, 'all');
wp_enqueue_style('main');
}
// Fires when scripts and styles are enqueued.
do_action('wp_enqueue_scripts', 'load_css');
function load_js() {
// Load only jquery
// wp_enqueue_script('jquery');
// Load bootstrap and jquery
wp_register_script('bootstrap', get_template_directory_uri() . '/js/bootstrap/bootstrap.min.js', ['jquery'], false);
wp_enqueue_script('bootstrap');
}
// Fires when scripts and styles are enqueued.
add_action('wp_enqueue_scripts', 'load_js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment