Support » Plugin: Freesoul Deactivate Plugins » deregister js/css in home or other page

  • Resolved cosmoweb

    (@cosmoweb)


    Hi,

    How can I deregister js/css in home or other page?

    Thank you for wonderful plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jose

    (@giuse)

    I @cosmoweb

    Thanks to you!

    With FDP you can disable an entire plugin on specific pages, but you can’t keep a plugin active and deregister its scripts.

    Disabling the entire plugin will also remove the database queries, hence improving the TTFB also when the page is not served by the cache, and of course, it will also remove its scripts and stylesheets.

    Do you need to keep a specific plugin active, but not its scripts and stylesheets?

    • This reply was modified 4 months ago by Jose.
    • This reply was modified 4 months ago by Jose.

    Hi Jose,

    thank you so much for reply,

    yes, i need to keep a specific plugin active deregister specific js/css in some page for example.

    Thanks

    Plugin Author Jose

    (@giuse)

    Hi @cosmoweb, you are welcome!

    So, FDP doesn’t support partial scripts deregistering. For Freesoul Deactivate Plugins, a plugin is ON or OFF with all its scripts and stylesheets. In your case, it can’t help you. Maybe you need a plugin like Asset CleanUp.

    If you want, they can also work together.
    Where you don’t need the entire plugins you can use Freesoul Deactivate Plugins, where you want only to deregister scripts and stylesheets, you keep the plugins active and use Assets CleanUp.

    Or, if it’s just for a few pages, a couple of lines of code in functions.php:

    function my_dequeue_styles() {
    	global $post;
    	$id1 = 425;
    	$id2 = 675;
    	if( is_object( $post ) && in_array( $post->ID,array( $id1,$id2 ) ) ){
    		wp_dequeue_style( 'style-handle' );
    		wp_deregister_style( 'style-handle' );
    	}
    }
    add_action( 'wp_print_styles', 'my_dequeue_styles' );
    
    function my_dequeue_scripts() {
    	global $post;
    	$id1 = 425;
    	$id2 = 675;	
        if( is_object( $post ) && in_array( $post->ID,array( $id1,$id2 ) ) ){
    		wp_dequeue_script( 'script-handle' );
    		wp_deregister_script( 'script-handle' );
    	}
    }
    add_action( 'wp_enqueue_scripts','my_dequeue_scripts' );

    Where you should replace the values of $id1, $id2… with the pages IDs (in this example 425 and 675), and style-handle and script-handle with the names used by the plugin that enqueued that stylesheets and scripts.

    I hope it helps.

    Plugin Author Jose

    (@giuse)

    Hi @cosmoweb
    I’m going to close this thread, if you decided to use FDP and have issues, don’t hesitate to open a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.