Last active
February 21, 2024 21:34
-
-
Save igorbenic/076b5e201e1d8d006dd894e83fbc037e to your computer and use it in GitHub Desktop.
Better WordPress Performance by Controlling Scripts | http://www.ibenic.com/better-wordpress-performance/
This file contains 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 | |
add_action( 'admin_enqueue_scripts', 'books_enqueue_scripts' ); | |
function books_enqueue_scripts( $hook ){ | |
$hook_scripts = false; | |
if( $hook_suffix == "post-new.php" && isset( $_GET["post_type"] ) && $_GET["post_type"] == "books" ){ | |
$hook_scripts = true; | |
} | |
if( $hook_suffix == "post.php" && isset( $_GET["post"] ) && get_post_type( $_GET["post"] ) == "books" ) { | |
$hook_scripts = true; | |
} | |
if( $hook_scripts ){ | |
wp_enqueue_script( 'jquery-ui-datepicker' ); | |
wp_enqueue_script( 'gasap-admin-js', plugins_dir_url( __FILE__ ) . '/admin/assets/js/books.js', array('jquery') ); | |
} | |
} |
This file contains 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 | |
// Enqueue Theme scripts and Styles | |
add_action( 'wp_enqueue_scripts', 'my_theme_scripts' ); | |
function my_theme_scripts() { | |
// Add Style | |
wp_enqueue_style( 'my-theme-stylesheet', get_stylesheet_uri(), false ); | |
// Add Script that depends on jQuery, is version 1.0 and will render in footer | |
wp_enqueue_script( 'my-theme-js', get_stylesheet_directory_uri() . '/js/my-theme.js', array( 'jquery' ), '1.0', true ); | |
} | |
// Enqueue Plugin scripts and Styles | |
add_action( 'wp_enqueue_scripts', 'my_plugin_scripts' ); | |
// Define constant on the main plugin file so that we can reference anything from our plugin | |
define( 'MY_PLUGIN_URI', plugin_dir_url( __FILE __) ); | |
function my_plugin_scripts() { | |
// Add Style - http://my-wp-site.com/wp-content/plugins/my-plugin/css/my-plugin.css | |
wp_enqueue_style( 'my-plugin-stylesheet', MY_PLUGIN_URI . 'css/my-plugin.css', false ); | |
// Add Script that depends on jQuery, is version 1.0 and will render in footer | |
// - http://my-wp-site.com/wp-content/plugins/my-plugin/js/my-plugin.js | |
wp_enqueue_script( 'my-plugin-js', MY_PLUGIN_URI . '/js/my-plugin.js', array( 'jquery' ), '1.0', true ); | |
} | |
This file contains 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 | |
add_action( 'init', 'ibenic_show_scripts'); | |
function ibenic_show_scripts(){ | |
global $wp_filter; | |
if( is_admin() ){ | |
return; | |
} | |
print_r( $wp_filter['wp_enqueue_scripts']); | |
die(); | |
} |
This file contains 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
Array | |
( | |
[0] => admin-bar | |
[1] => wc-add-to-cart | |
[2] => woocommerce | |
[3] => wc-cart-fragments | |
[4] => twentysixteen-html5 | |
[5] => twentysixteen-skip-link-focus-fix | |
[6] => twentysixteen-script | |
) |
This file contains 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
Array | |
( | |
[0] => admin-bar | |
[1] => woocommerce-layout | |
[2] => woocommerce-smallscreen | |
[3] => woocommerce-general | |
[4] => twentysixteen-fonts | |
[5] => genericons | |
[6] => twentysixteen-style | |
[7] => twentysixteen-ie | |
[8] => twentysixteen-ie8 | |
[9] => twentysixteen-ie7 | |
) |
This file contains 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 | |
Array | |
( | |
[5] => Array | |
( | |
[siteorigin_panels_default_styles_register_scripts] => Array | |
( | |
[function] => siteorigin_panels_default_styles_register_scripts | |
[accepted_args] => 1 | |
) | |
) | |
[1] => Array | |
( | |
[siteorigin_panels_enqueue_styles] => Array | |
( | |
[function] => siteorigin_panels_enqueue_styles | |
[accepted_args] => 1 | |
) | |
) | |
[10] => Array | |
( | |
[siteorigin_panels_live_edit_link_style] => Array | |
( | |
[function] => siteorigin_panels_live_edit_link_style | |
[accepted_args] => 1 | |
) | |
[WC_Frontend_Scripts::load_scripts] => Array | |
( | |
[function] => Array | |
( | |
[0] => WC_Frontend_Scripts | |
[1] => load_scripts | |
) | |
[accepted_args] => 1 | |
) | |
[twentysixteen_scripts] => Array | |
( | |
[function] => twentysixteen_scripts | |
[accepted_args] => 1 | |
) | |
[twentysixteen_color_scheme_css] => Array | |
( | |
[function] => twentysixteen_color_scheme_css | |
[accepted_args] => 1 | |
) | |
) | |
[11] => Array | |
( | |
[twentysixteen_page_background_color_css] => Array | |
( | |
[function] => twentysixteen_page_background_color_css | |
[accepted_args] => 1 | |
) | |
[twentysixteen_link_color_css] => Array | |
( | |
[function] => twentysixteen_link_color_css | |
[accepted_args] => 1 | |
) | |
[twentysixteen_main_text_color_css] => Array | |
( | |
[function] => twentysixteen_main_text_color_css | |
[accepted_args] => 1 | |
) | |
[twentysixteen_secondary_text_color_css] => Array | |
( | |
[function] => twentysixteen_secondary_text_color_css | |
[accepted_args] => 1 | |
) | |
) | |
) |
This file contains 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 | |
add_action( 'init', 'my_theme_remove_siteorigin', 99); | |
function my_theme_remove_siteorigin(){ | |
remove_action( 'wp_enqueue_scripts', 'siteorigin_panels_live_edit_link_style', 10 ); | |
remove_action( 'wp_enqueue_scripts', 'siteorigin_panels_default_styles_register_scripts', 5 ); | |
remove_action( 'wp_enqueue_scripts', 'siteorigin_panels_enqueue_styles', 1 ); | |
} |
This file contains 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 | |
add_action( 'wp_enqueue_scripts', 'ibenic_remove_woocoomerce_in_frontpage', 97 ); | |
function ibenic_remove_woocoomerce_in_frontpage(){ | |
// Return if it is not the front page | |
if( ! is_front_page() ){ | |
return; | |
} | |
// Remove Scripts | |
wp_dequeue_script( 'wc-add-to-cart' ); | |
wp_dequeue_script( 'woocommerce' ); | |
wp_dequeue_script( 'wc-cart-fragments' ); | |
// Remove Styles | |
wp_dequeue_style( 'woocommerce-layout' ); | |
wp_dequeue_style( 'woocommerce-smallscreen' ); | |
wp_dequeue_style( 'woocommerce-general' ); | |
} |
This file contains 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
Scripts to Load | |
Array | |
( | |
[0] => admin-bar | |
[4] => twentysixteen-html5 | |
[5] => twentysixteen-skip-link-focus-fix | |
[6] => twentysixteen-script | |
) | |
Styles to Load | |
Array | |
( | |
[0] => admin-bar | |
[4] => twentysixteen-fonts | |
[5] => genericons | |
[6] => twentysixteen-style | |
[7] => twentysixteen-ie | |
[8] => twentysixteen-ie8 | |
[9] => twentysixteen-ie7 | |
) |
This file contains 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 | |
add_action( 'wp_enqueue_scripts', 'ibenic_show_scripts_handles', 99); | |
function ibenic_show_scripts_handles(){ | |
// Show only in front | |
if( is_admin() ){ | |
return; | |
} | |
// Get WP_Scripts Object | |
$wp_scripts = wp_scripts(); | |
// Print Queued Handles | |
print_r( $wp_scripts->queue ); | |
die(); | |
} |
This file contains 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 | |
add_action( 'wp_enqueue_scripts', 'ibenic_show_styles_handles', 99); | |
function ibenic_show_styles_handles(){ | |
// Show only in front | |
if( is_admin() ){ | |
return; | |
} | |
// Get WP_Scripts Object | |
$wp_styles = wp_styles(); | |
// Print Queued Handles | |
print_r( $wp_styles->queue ); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment