Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix home page performance #339

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading