Combine and Minify CSS

function combine_css_files() { wp_enqueue_style(‘combined-styles’, get_template_directory_uri() . ‘/css/combined.min.css’, array(), null, ‘all’); // Dequeue individual files if they are now part of the combined file wp_dequeue_style(‘style-one’); wp_dequeue_style(‘style-two’); } add_action(‘wp_enqueue_scripts’, ‘combine_css_files’);Continue reading

Defer or Async CSS Loading

function async_css($tag, $handle) { // Add ‘async’ to CSS file that you want to load asynchronously if (‘your-style-handle’ !== $handle) { return $tag; } return str_replace(‘ href’, ‘ async=”async” href’, $tag); } add_filter(‘style_loader_tag’, ‘async_css’, 10, 2);Continue reading

Dequeue CSS files conditionally

function remove_unused_css() { // Check if it’s not the homepage or not a specific post type if ( !is_front_page() && !is_page(‘your-page-slug’) ) { wp_dequeue_style(‘unused-stylesheet-handle’); wp_deregister_style(‘unused-stylesheet-handle’); } } add_action(‘wp_enqueue_scripts’, ‘remove_unused_css’);Continue reading

Show ‘NEW’ Badges for Recently Added Items in WooCommerce

/** * Snippet Name: Show ‘NEW’ Badges for Recently Added Items in WooCommerce * Snippet Author: wdxtechnologies.com */ // Show the NEW badge on the archive loop item add_action( ‘woocommerce_after_shop_loop_item_title’, ‘ecommercehints_product_archive_new_badge’, 1 ); function ecommercehints_product_archive_new_badge() { global $product; $days_to_show =…Continue reading

Remove Unused Javascript

//This has been syncronised 123// function wp_remove_scripts() { // check if user is admina if (current_user_can( ‘update_core’ )) { return; } else { // Check for the page you want to target if ( is_page( ‘homepage’ ) ) { //…Continue reading

Delete Woocommerce images after deleting product

// Automatically Delete Woocommerce Images After Deleting a Product add_action( ‘before_delete_post’, ‘delete_product_images’, 10, 1 ); function delete_product_images( $post_id ) { // Check if user has the capability to delete products if ( !current_user_can( ‘delete_products’ ) ) { return; } $product…Continue reading