• Resolved kevinc81

    (@kevinc81)


    Hi,

    First of all, congratulations on your plugin which works really well.

    Currently, in the scritps to exclude from Autoptimize I have: seal.js,js/jquery/jquery.js,leaflet.js
    However, I would like js/jquery/jquery.js to be partially excluded, not on my entire website.
    I would like jquery to be excluded from Autoptimize only in articles (parts of my website with the conditional marker ‘is_single()’ )
    Is there a function for this (like for wp_rocket to disable its lazyload on specific parts of a website https://docs.wp-rocket.me/article/16-disabling-lazyload-on-specific-posts ) ?

    I thank you in advance for your answer.

    Best regards,

    Kévin CAROL

    • This topic was modified 6 years, 3 months ago by kevinc81.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter kevinc81

    (@kevinc81)

    Hi,

    Maybe I wasn’t clear enough in my explanations

    I would like to exclude from optimization js/jquery/jquery.js only for article pages (those parts of the website that have the conditional tag ‘is_single()’) )

    Is there a function, to be placed in the functions.php file or elsewhere, of this type? :

    function __deactivate_autoptimize_jquery_if_page()
    {
    	if( is_single() ) {
    		add_filter( 'do_autoptimize_jquery', '__return_false' );
    	}
    }
    *this function is not correct, it is just to illustrate my request

    Best regards,

    Kévin CAROL

    • This reply was modified 6 years, 3 months ago by kevinc81.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    sorry @kevinc81; I didn’t receive a mail notification of your questoin. so yes, AO has a lot of filters and in your case you could use autoptimize_filter_js_exclude for that, something like this (warning; not tested):

    add_filter('autoptimize_filter_js_exclude','jquery_toggle');
    function jquery_toggle($in) {
        if ( is_single() ) {
            return $in.',js/jquery/jquery.js';
        else {
            return $in;
        }
    }
    

    hope this helps,
    frank

    Thread Starter kevinc81

    (@kevinc81)

    Hi,

    First of all, thank you for your answer.
    It’s okay for the delay, I will have written a reminder in a few days if I hadn’t received a reply !

    I added the missing “}” to your code and placed it in the functions.php file

    Unfortunately this code is problematic, as soon as I validate the modification, I can no longer access any page of the administrator part of the site, the famous “white screen admin panel of death”. However, the site remained accessible as a visitor.
    I had to restore a backup via my FTP FileZilla.

    I don’t know what could have caused a bug so much in this code, I’m not a professional in this field…

    I will therefore need your help again, and I thank you in advance.

    Best regards,

    Kévin CAROL

    • This reply was modified 6 years, 3 months ago by kevinc81.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    tested and works with the extra {;

    add_filter('autoptimize_filter_js_exclude','jquery_toggle');
    function jquery_toggle($in) {
        if ( is_single() ) {
            return $in.',js/jquery/jquery.js';
    	} else {
            return $in;
        }
    } 

    fyi; I use the code snippets plugin to add code snippets and I tick the “Only run on site front-end” option, risks of white screens are minimal and if things go south simply renaming the code snippet plugin’s folder (wp-content/plugins/code-snippets) over FTP should bring things back to life ??

    Thread Starter kevinc81

    (@kevinc81)

    Hi,

    In this way it has worked perfectly ??

    Thanks to your help, my website has saved more than 2 seconds of loading on pages where jquery is not necessary !

    Thank you for everything

    Best regards,

    Kévin CAROL

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you’re welcome Kévin, feel free to leave a review of the plugin and support here! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Partially exclude the jquery script from Autoptimize’ is closed to new replies.