Skip to content

Commit

Permalink
Update functions.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Finland93 authored Dec 29, 2024
1 parent 3436f98 commit c37fbad
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ function speedpress_enqueue_favicons() {
}
add_action('wp_head', 'speedpress_enqueue_favicons');

// Remove jQuery if WooCommerce is not installed
function speedpress_conditional_jquery() {
if (!class_exists('WooCommerce')) {
// If WooCommerce is not installed, deregister jQuery
wp_deregister_script('jquery');
} else {
// If WooCommerce is installed, ensure jQuery is enqueued
wp_enqueue_script('jquery');
}
}
add_action('wp_enqueue_scripts', 'speedpress_conditional_jquery', 5); // Run early to ensure jQuery is deregistered before being enqueued

// Enqueue styles and scripts
function speedpress_enqueue_styles_scripts() {
// Styles
Expand All @@ -17,26 +29,22 @@ function speedpress_enqueue_styles_scripts() {

// Scripts
wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/js/bootstrap.bundle.min.js', array(), '5.3.0', true);

// Ensure jQuery is loaded only if WooCommerce is active
if ( class_exists( 'WooCommerce' ) ) {
wp_enqueue_script('jquery');
}
}
add_action('wp_enqueue_scripts', 'speedpress_enqueue_styles_scripts');


// Remove jQuery Migrate
// Remove jQuery Migrate if jQuery is loaded
function speedpress_remove_jquery_migrate($scripts) {
if (isset($scripts->registered['jquery'])) {
$script = $scripts->registered['jquery'];
if ($script->deps) {
// Remove jQuery Migrate if jQuery is being loaded
$script->deps = array_diff($script->deps, array('jquery-migrate'));
}
}
}
add_action('wp_default_scripts', 'speedpress_remove_jquery_migrate');


// Setup theme features
function speedpress_setup_theme() {
register_nav_menus(array(
Expand Down

0 comments on commit c37fbad

Please sign in to comment.