How to Remove Styles, Scripts, and More from your WordPress Parent Theme

WordPress Parent Child Theme

WordPress Parent Child ThemeOccasionally, I use a parent-child theme relationship to build sites. Many times, the parent themes come loaded with extras that get in the way, slow down the site, and just don’t need to be there. Here are few tips for cleaning up that extra bloat.

The following post provides code examples for adjusting parent theme functionality. We recommend creating a custom functionality plugin to place code rather than the functions.php theme file. If you are a novice, please be careful and always remember to backup. Note that we also provide a number of quality plugins as well. Disclaimer aside, lets get into the fun stuff.

De-enqueue Extra WordPress Parent Theme JavaScripts

One of the most common gripes I have with many themes is the number of JS files they output. Who wants smooth scroll anyways? I sure don’t. Let the browser handle that.  Take a look at the source of your parent theme. If you see extra scripts in there you don’t need, like a smooth scroll plugin, then remove them. In order to remove them, you need to do two things:

  1. Find the “handle” of the script or style
  2. De-enqueue the script or style with that handle

How do I find the handle of the script or style in my site?

There are a couple ways you can do this:

  1. With a plugin: Using the Debug Bar plugin and the add-on Debug Bar List Script & Style Dependencies we can output which scripts are loaded in each page of your site. The first line is the “handle” and the second line is exactly where you can find that script. The output is very nice:
  2. Using an IDE: In PHPStorm I typically run a search for wp_enqueue_script through the parent theme directory. This will tell me all the scripts that are being output and I can unhook them from there.
  3. Using code: Here’s an excellent function from Ngoc Nguyen that will print out the script handles. You can insert this into a page template, create a page with that template, then visit that page and you’ll see the list output really nicely on the page. Just make sure you don’t use this on a live site:
    function wpcustom_inspect_scripts_and_styles() {
    	global $wp_scripts;
    	global $wp_styles;
    	// Runs through the queue scripts
    	foreach( $wp_scripts->queue as $handle ) :
    		$scripts_list .= $handle . ' | ';
    	// Runs through the queue styles
    	foreach( $wp_styles->queue as $handle ) :
    		$styles_list .= $handle . ' | ';
    	printf('Scripts: %1$s  Styles: %2$s', 
    add_action( 'wp_print_scripts', 'wpcustom_inspect_scripts_and_styles' );

How Do I De-Enqueue the Scripts?

Now that you have the handles of the styles or scripts that you want to de-enqueue, you’ve got to actually de-enqueue them. Here’s a few methods for doing that.

Using Code

I prefer to use code to keep the plugins to a minimum. Fortunately, de-enqueuing scripts and styles in WordPress is very easy. Add this to your custom functionality plugin:

 * Dequeue the Parent Theme scripts.
 * Hooked to the wp_print_scripts action, with a late priority (100),
 * so that it is after the script was enqueued.
function my_site_WI_dequeue_script() {
	wp_dequeue_script( 'comment-reply' ); //If you're using disqus, etc.
	wp_dequeue_script( 'jquery_ui' ); //jQuery UI, no thanks!
	wp_dequeue_script( 'fancybox' ); //Nah, I use FooBox
	wp_dequeue_script( 'wait_for_images' );
	wp_dequeue_script( 'jquery_easing' );
	wp_dequeue_script( 'swipe' );
	wp_dequeue_script( 'waypoints' );

add_action( 'wp_print_scripts', 'my_site_WI_dequeue_script', 100 );

 * Dequeue the Parent Theme styles.
 * Hooked to the wp_enqueue_scripts action, with a late priority (100),
 * so that it runs after the parent style was enqueued.

function give_dequeue_plugin_css() {
add_action('wp_enqueue_scripts','give_dequeue_plugin_css', 100);

For more information on wp_dequeue_script, please see the Codex article.

But sometimes you want to deregister a script or style only on certain pages. For example, WooCommerce likes to load scripts on every page of the site. This can cause load times to go up. Here’s an article where I explain, through the use of conditionals, how to load WooCommerce scripts conditionally. You can see in the comments people are experiencing significant reductions in load times.

Using a Plugin

Head Cleaner is plugin for removing scripts and CSS from your WordPress header and footer. Simply download the plugin, go to Settings > Head Cleaner, and select the scripts you don’t need output. If you’re not seeing and scripts or styles, try going to the frontend and refreshing a few times so the plugin can read the hooks.


Deregistering an Unwanted Post Type

Let’s say you’ve purchased a Portfolio theme and it has a post type “testimonials”, but you don’t have any need for it this post type. Rather than having this post type sitting around on your site, let’s de-register it so we don’t have to see it every time we login to the admin panel.

Code Method: To deregister a post type programmatically here’s a nifty function provided by Nacin:

if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type( $post_type ) {
    global $wp_post_types;
    if ( isset( $wp_post_types[ $post_type ] ) ) {
        unset( $wp_post_types[ $post_type ] );
        return true;
    return false;

Then to use it simply run the function with your post type as the parameter:

unregister_post_type( 'testimonials' );

Plugin Method: Adminimize is a good plugin for all aspects of customizing your WordPress admin panel, including removing post types. Please note: I believe the plugin will simply unhook the menu item from display rather than deregistering it though.


Removing Certain Post Type Features

Perhaps you don’t want to remove the entire “testimonials” post type, just a feature of the post type, such as excerpt or revisions support. remove_post_type_support() is a quick and easy function that will allow you to do just that:

add_action( 'init', 'my_wi_custom_init' );
function my_wi_custom_init() {
     remove_post_type_support( 'testimonials', 'excerpt' );
     remove_post_type_support( 'testimonials', 'revisions' );

For more about the remove_post_type_support function check out the Codex article.

Deregistering Sidebars You Don’t Need

Your child theme may not require certain registered sidebars from the theme’s parent. Let’s keep with our strategy of keeping our admin as clean and lean as possible and deregister unnecessary sidebars. The following code will prevent unwanted sidebars from appears under Appearances > Widgets in your WordPress admin:

function go_away_extra_sidebars() {

    if ( is_admin() && current_user_can('editor') ) {
        unregister_sidebar( 'my_custom_widget_area' ); //parameter is sidebar ID

add_action('widgets_init', 'go_away_extra_sidebars', 20);

The parameter expected for the unregister_sidebar is the ID of the sidebar when it was added.

Remove Custom Widgets from a WordPress Parent Theme

Some theme’s come with widgets baked in. A few may be useful, others not. So, let’s cut the fat and remove the ones we do not need. Typically, widgets are declared in a PHP class that extends the WP_Widget class. Find out the extended class name for the widgets you wish the remove by searching the parent theme for the aforementioned class name. Once you find them out use the following function to remove them:

add_action( 'widgets_init', 'wi_parent_unregister_widgets', 10 );
function wi_parent_unregister_widgets() {
    // remove (some) WordPress default Widgets
    unregister_widget( 'WP_Widget_Pages' );
    unregister_widget( 'WP_Widget_Calendar' );
    // remove Parent registered Widget
    unregister_widget( 'ParentWidgetName' );


What Else? Well, actually… a lot!

Themes have a lot of power to extend your WordPress site. Because of this, there may be other items that you wish to remove from a Parent theme such as:

  • Menus
  • Shortcodes
  • Image Sizes
  • Metaboxes
  • Actions & Filters

Here’s an excellent article from Tutsplus that provides more examples and functions for controlling parent theme behavior from within a child theme.

Thanks for stopping by! If you have any questions or comments then please leave one below.

Now in Video Format

The fine folks at Webucator put together a detailed Video tutorial based on this article. Enjoy!

5 thoughts on “How to Remove Styles, Scripts, and More from your WordPress Parent Theme

  1. Hey, thanks for sharing Devin, I just enjoyed the read of the Mailchimp article you sent out today. Your sharing of insights is fantastic. Bookmarked this page as I have a few themes in use that will find handy to deregister some crappy unwanted CPT’s that I will never use.

Leave a Reply

Your email address will not be published. Required fields are marked *