How to remove unnecessary scripts and CSS files from a theme?

Not all scripts and CSS files that themes and plugins use are needed. So there is optimization potential here, which is especially advantageous when loading the website.

1.) The first step is to find out the ID. This is best done with the Inspector.

<link rel='stylesheet' id='default_styles-css' href='https://example.com/wp/wp-content/themes/example/style.css' type='text/css' media='all' />

2. If the ID is not displayed, you can help yourself with the following script in the functions.php and then read the ID with the inspector in the head area.

/*
  Get Script and Style IDs
  Adds inline comment to your frontend pages
  View source code near the <head> section
  Lists only properly registered scripts
  @ https://digwp.com/2018/08/disable-script-style-added-plugins/
*/
function shapeSpace_inspect_script_style() {
  
  global $wp_scripts, $wp_styles;
  
  echo "\n" .'<!--'. "\n\n";
  
  echo 'SCRIPT IDs:'. "\n";
  
  foreach($wp_scripts->queue as $handle) echo $handle . "\n";
  
  echo "\n" .'STYLE IDs:'. "\n";
  
  foreach($wp_styles->queue as $handle) echo $handle . "\n";
  
  echo "\n" .'-->'. "\n\n";
  
}
add_action('wp_print_scripts', 'shapeSpace_inspect_script_style');

3. If the IDs of the desired elements are known, the actual part comes in which these are removed.

function disable_scripts_styles() {
  if (!is_page('checkout') && !is_page('purchase-confirmation') && !is_page('purchase-history') && !is_page('transaction-failed')) {
    wp_dequeue_script('beispiel01');
    wp_dequeue_style('beispiel02');
  }
  
  wp_dequeue_style('beispiel03');
}
add_action('wp_enqueue_scripts', 'disable_scripts_styles', 100);

If the above script does not work, the following is an alternative:

add_action( 'wp_enqueue_scripts', 'yith_wcbm_dequeue_google_fonts',999 );

function yith_wcbm_dequeue_google_fonts(){
    wp_dequeue_style( 'HIER KOMMT DIE ID BEZEICHNUNG HINEIN' );
}
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.
  • Developed 2023
  • CMS WordPress
  • Status Completed

Just a Web-Developer

Creating a developer’s own website is always a big challenge. You want to integrate all the cool features and show all your skills. Therefore, it is rather called here to make cutbacks and to put the information in the foreground. I hope this is halfway successful here.
To add value, I’ve taken the „Helpful Code Snippets“ element form my old website and integrated a search function for them.

  • Developed 2022
  • CMS WordPress
  • Status Completed

Tatort Ruhrpott

A few years ago I had the idea for a photo project. I wanted to photograph crime scenes from the Ruhr region and show how these places look today. During the Corona Pandemic 2021, I started taking the photos and at the beginning of 2022, I started implementing the corresponding website.

  • Developed 2018
  • CMS WordPress
  • Status Completed

CMS Geek

CMS Geek was a website project that I started in 2018 and was supposed to introduce users to the functions of WordPress through explanatory videos. In addition to a blog that informed about the latest news about WordPress and Joomla, there were also helpful code solutions to common WordPress, html and CSS problems.

Due to the lack of time to produce more explainer videos, I discontinued this project in spring 2023. I have taken over the code snippets for Just-a-Web-Developer, updated them and will continue to expand them.