with some code; sure, disable “defer inline” and use a code snippet to enable it for blogposts (is_single) with the autoptimize_js_filter_defer_inline filter? π
Thank you π
By the way is there a website where I could find all the filters I could use with Autoptimize? I tried google, but couldn’t find it.
github search could be a starting place? π
Sorry, I’m not a professional web developer, more like a hobbyist and not very familiar with github, but I’m doing my best and learning new things, thank you π
I was wondering if I can have AO aggregate js files with a certain list of exclusions by default, but at the same time disable aggregation and use defer js option with a shorter exclusion list for blog posts? For that I’ve tried using this code:
add_filter('autoptimize_filter_js_exclude','my_ao_exclusion_list');
function my_ao_exclusion_list($in) {
if ( !is_singular(array( 'post' )) ) {
return $in.'lazyload.min.js, js/jquery/jquery.min.js, js/jquery/jquery.js';
} else {
return $in.'lazyload.min.js';
}
}
add_filter('autoptimize_filter_js_dontaggregate','my_ao_dontaggregate');
function my_ao_dontaggregate() {
if ( is_singular(array( 'post' )) ) {
return true;
} else {
return false;
}
}
add_filter('autoptimize_filter_js_defer_not_aggregate','my_ao_defer_not_aggregate');
function my_ao_defer_not_aggregate () {
if ( is_singular(array( 'post' )) ) {
return true;
} else {
return false;
}
}
add_filter('autoptimize_js_filter_defer_inline','my_ao_defer_inline');
function my_ao_defer_inline () {
if ( is_singular(array( 'post' )) ) {
return true;
} else {
return false;
}
}
It did the trick for blog posts, however other pages do not aggregate js files.
Do you have any suggestions on what am I doing wrong here and if is it even possible what I’m attempting to do?
Thanks.
-
This reply was modified 4 years, 10 months ago by
woorooo.
-
This reply was modified 4 years, 10 months ago by
woorooo.
-
This reply was modified 4 years, 10 months ago by
woorooo.
Does anything change when you change
} else {
return;
into
} else {
return false;
Thank you, I’ve found an error when naming the function with the exclusion list, I’ve also updated it up there and it seems to work as expected. Thank you so much π
great job, enjoy the rush of seeing your code work Roman! π
And feel free to leave a review of the plugin and support here! π