• Resolved utrenkner

    (@utrenkner)


    I like FVM a lot – it works just great!

    Just one question: Is there any way to disable FVM for a single page or template?

    Background of this question: I have one page, which uses disgusting table based layout with many conditional comments (an e-mail-newsletter designed with MJML, to please all those e-mail clients not understanding modern CSS). I absolutely do not want any plugin – including FVM – to mess with that code. Could I disable the plugin for this page (this template)? Or specifically: Could I disable the HTML minification, but use it on all other pages/posts?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Raul P.

    (@alignak)

    Its not supported by default, however you can code an auxiliary function that runs when the requested url, matches some specific pattern OR by page number / title using conditional tags.

    You need to know a little of php coding or hire a developer for that though.
    Once you come up with the logic to run something on that url, you can call these filters to prevent FVM from doing anything on that page:

    remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
    remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', 9.999999 ); 
    remove_action('wp_print_styles', 'fastvelocity_min_merge_header_css', PHP_INT_MAX ); 
    remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_css', 9.999999 );
    remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
    remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
    remove_action('init', 'fastvelocity_min_disable_wp_emojicons');
    remove_action('template_redirect', 'fastvelocity_min_html_compression_start', PHP_INT_MAX);
    remove_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', 10, 2);
    remove_filter('script_loader_tag', 'fastvelocity_min_defer_js', 10, 3); 
    Thread Starter utrenkner

    (@utrenkner)

    @alignak Thank you so much!

    It took a little reading/trying to find out, where to put the remove_action. But now it works as intended! Great!

    Maybe someone else will need this info too: I put this in the functions.php of my child theme to prevent html minification on the page with the stub “email-newsletter”.

    add_action('template_redirect', 'remove_htmlmin_in_newsletter');
    
    function remove_htmlmin_in_newsletter() {
        if(is_page('email-newsletter')){
            remove_action('template_redirect', 'fastvelocity_min_html_compression_start', PHP_INT_MAX);
        }
    }

    thanks for sharing @utrenkner.

    I had a similar issue but, in my case, it was CSS optimization which was causing some trouble.

    In order to fix, I had to use some hooks that have not been mentioned in this thread:

    
    remove_action('wp_footer', 'fvm_add_loadcss', PHP_INT_MAX);
    remove_action('admin_enqueue_scripts', 'fastvelocity_min_load_admin_jscss', PHP_INT_MAX);
    remove_action('style_loader_tag', 'fastvelocity_optimizecss', PHP_INT_MAX);
    

    In case it can help someone else, this is the code I had to add to my functions.php:

    
    function disable_fvm_functionality() {
    		$current_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    		if( strpos($current_path, '/newsletter/') !== false ) {
    			remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
    			remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', PHP_INT_MAX);
    			remove_action('wp_print_styles', 'fastvelocity_min_merge_header_css', PHP_INT_MAX );
    			remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_css', PHP_INT_MAX);
    			remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
    			remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
    			remove_action('init', 'fastvelocity_min_disable_wp_emojicons', PHP_INT_MAX);
    			remove_action('template_redirect', 'fastvelocity_min_html_compression_start', PHP_INT_MAX);
    			remove_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', PHP_INT_MAX);
    			remove_filter('script_loader_tag', 'fastvelocity_min_defer_js', PHP_INT_MAX);
    			remove_action('wp_footer', 'fvm_add_loadcss', PHP_INT_MAX);
    			remove_action('admin_enqueue_scripts', 'fastvelocity_min_load_admin_jscss', PHP_INT_MAX);
    			remove_action('style_loader_tag', 'fastvelocity_optimizecss', PHP_INT_MAX);
        }
    }
    add_action('template_redirect', 'disable_fvm_functionality');
    

    In my case, I’ve disabled the plugin for all pages that match “/newsletter/” in the URL (replace “/newsletter/” according to your needs or use a different expression to match against).

    Plugin Author Raul P.

    (@alignak)

    Note that the remove_action('admin_enqueue_scripts', 'fastvelocity_min_load_admin_jscss', PHP_INT_MAX); is for the wp-admin only, and should not be needed on the frontend.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disable FVM on a single page?’ is closed to new replies.