Last active
September 17, 2024 15:59
-
-
Save atomjoy/9fdc27277e573804edc8bc86336f520d to your computer and use it in GitHub Desktop.
Load scripts and style with do_action hooks in Wordpress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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