Skip to content

Commit

Permalink
Optimize css resource loading
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Oct 27, 2023
1 parent 2f062c1 commit ec6922a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/wp-content/themes/wporg-main-2022/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
* Actions and filters.
*/
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_dequeue_assets' );
add_action( 'init', __NAMESPACE__ . '\register_shortcodes' );
add_filter( 'wp_img_tag_add_loading_attr', __NAMESPACE__ . '\override_lazy_loading', 10, 2 );
add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' );
add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\use_parent_page_title', 10, 3 );
add_filter( 'render_block_data', __NAMESPACE__ . '\update_header_template_part_class' );
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );

// Remove Jetpack CSS on frontend
add_filter( 'jetpack_implode_frontend_css', '__return_false', 99 );

/**
* Enqueue scripts and styles.
*/
Expand Down Expand Up @@ -96,6 +100,16 @@ function enqueue_assets() {
}
}

/**
* Dequeue or deregister some scripts and styles on frontend for performance.
*/
function maybe_dequeue_assets() {
if ( ! is_user_logged_in() && is_front_page() ) {
wp_deregister_style( 'dashicons' );
wp_deregister_style( 'wp-mediaelement' );
}
}

/**
* Load the shortcodes available for the theme.
*/
Expand Down

0 comments on commit ec6922a

Please sign in to comment.