Get per page critical CSS from custom field
-
Hi Frank,
Thanks for the great work.
I want to override the critical CSS for pages & this CSS is added to a custom field. I added the below code, but I think there’s some issue as I see there are multiple CSS files. I am not sure if this is how it should be(Please correct me if I am wrong).
I just want to override the critical CSS I have added to autoptimize settings if $custom_critical_css has a value. I think there’s a problem with my code or it can be better. Thank you for your time.
add_filter('autoptimize_filter_css_defer_inline','my_ao_css_defer_inline',10,1); function my_ao_css_defer_inline($inlined) { $custom_critical_css = get_post_meta( get_the_ID() , 'custom_critical_css' , true ); if (is_page() && $custom_critical_css) { return $custom_critical_css; // overwrite default a-t-f CSS } else { return $inlined; // use default a-t-f CSS for all other types } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get per page critical CSS from custom field’ is closed to new replies.