Remove scripts/styles from theme


#1

Hi,
I would like to remove some css and script from theme, what is not needed.

I added this to function.php and it works

function wp_remove_scripts() {
wp_dequeue_style( 'style' );
wp_deregister_style( 'style' );

wp_dequeue_script( 'script' );
wp_deregister_script( 'script' );

}
add_action( 'wp_enqueue_scripts', 'wp_remove_scripts', 20 );

Something similar works too :slight_smile: so I really appreciate any help, what is the right way for this?

For example this worked also

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

function my_deregister_styles() {
	wp_deregister_style( 'style' );
}


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

function my_deregister_javascript() {
	wp_deregister_script( 'javascript' );
}

Thanks in advance


(Jimmy Smutek) #2

Hey Peter, either one of those should be fine but I’d go with the first since it’s simpler (all related functions in one action) and it’s structured the way add_action is defined in the Codex, with the functions being listed before the action that fires them.

I’m not sure what significance the different priorities would make in this particular case. It would be great if someone with more experience would weigh in.


(Pascal Birchler) #3

You should always use the wp_enqueue_scripts hooks for scripts and styles, so I’d go with the first one. Plus the reasons Jimmy said already.


#4

Thank you :ok_hand:


#5

ok, do not laugh me, if I do it completely wrong, anyway I try to remove scripts and style from theme Make.
In child theme function.php i just added

function wp_remove_scripts() {

wp_dequeue_style( 'ttfmake-print-style' );
wp_deregister_style( 'ttfmake-print-style' );

wp_dequeue_script( 'ttfmake-fitvids' );
wp_deregister_script( 'ttfmake-fitvids' );

wp_dequeue_script( 'ttfmake-cycle2' );
wp_deregister_script( 'ttfmake-cycle2' );

}
add_action( 'wp_enqueue_scripts', 'wp_remove_scripts', 20 );

nothing more …

With this it removes also ttfmake-global script :skull:


(Jimmy Smutek) #6

Sorry but I’m not familiar with Make. If I get a chance I’ll grab a copy, take a look and see if I can help.

Also, no one is going to laugh at you for asking questions. Anyone that does isn’t worth your time to even worry about.

Keep learning and doing your thing! :slight_smile:


#7

So today I moved to this

function wp_remove_scripts() {

	wp_deregister_script( 'ttfmake-cycle2' );
	wp_register_script( 'ttfmake-cycle2', '', false, false );

	wp_deregister_script( 'ttfmake-cycle2-center' );
	wp_register_script( 'ttfmake-cycle2-center', '', false, false );

	wp_deregister_script( 'ttfmake-cycle2-swipe' );
	wp_register_script( 'ttfmake-cycle2-swipe', '', false, false );

	wp_deregister_script( 'ttfmake-fitvids' );
	wp_register_script( 'ttfmake-fitvids', '', false, false );

	wp_deregister_style( 'ttfmake-print-style' );
	wp_register_style( 'ttfmake-print-style', '', false, false );
}
add_action( 'wp_enqueue_scripts', 'wp_remove_scripts' );

This works for now, not sure if this is right way.

Using this plugin I see there are some dependencies, so will see if this is not too much for me.
I can always move to Hellish Simplicity there is nothing to remove :wink: