/** * PERFORMANCE * Trims assets that were loading on every page regardless of use. */ /** * Post Grid (plugin) is only used inside single listing/holding templates and * anywhere the [post_grid] shortcode appears. Everywhere else its 8 scripts and * 7 stylesheets are dead weight in the . */ function omg_page_uses_post_grid() { if (is_admin()) { return true; } if (is_singular(array('listing', 'holding', 'holdings'))) { return true; } if (is_archive() || is_search() || is_404()) { return true; // unknown templates: leave the plugin alone } $post = get_post(); if ($post && (has_shortcode($post->post_content, 'post_grid') || strpos($post->post_content, 'post_grid') !== false)) { return true; } return (bool) apply_filters('omg_page_uses_post_grid', false); } add_action('wp_enqueue_scripts', 'omg_trim_post_grid_assets', 100); function omg_trim_post_grid_assets() { if (omg_page_uses_post_grid()) { return; } foreach (array('post_grid_scripts', 'jquery.mixitup.min', 'mixitup-multifilter', 'jquery.mixitup-pagination', 'masonry.pkgd.min', 'imagesloaded.pkgd.js', 'jquery-scrollto', 'owl.carousel.min') as $handle) { wp_dequeue_script($handle); } foreach (array('post_grid_style', 'owl.carousel.min', 'font-awesome', 'style-woocommerce', 'style.skins', 'style.layout', 'style.animate', 'font-awesome5') as $handle) { wp_dequeue_style($handle); } } /** * WordPress emoji polyfill: one script + inline JS/CSS on every page, unused. */ add_action('init', function() { remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); add_filter('emoji_svg_url', '__return_false'); add_filter('tiny_mce_plugins', function($plugins) { return is_array($plugins) ? array_diff($plugins, array('wpemoji')) : array(); }); }); /** * Dashicons are only needed for the admin bar. */ add_action('wp_enqueue_scripts', function() { if (!is_user_logged_in()) { wp_dequeue_style('dashicons'); wp_deregister_style('dashicons'); } }, 100); /** * Elementor was printing CSS for Roboto, Roboto Slab, Yanone, Poppins and * Oswald. Nothing on the site renders them; all type comes from Typekit. */ add_filter('elementor/frontend/print_google_fonts', '__return_false'); /** * Cornerstone/X-theme leftovers and jQuery Migrate are left alone on purpose: * the Gravity Forms reCAPTCHA add-on still depends on legacy jQuery behaviour. */