Using inline and defer API override global per page
-
Hello Frank,
I am taking your suggestion of using the API to override the critical CSS per page and I found a code awhile ago that is supposed to fix my problem but is not overriding the whole global critical CSS.
This is the code I am using:
add_filter('autoptimize_filter_css_defer_inline','my_ao_css_defer_inline',10,1); function my_ao_css_defer_inline($inlined) { if (strpos($_SERVER['REQUEST_URI'],'/how-it-works/')!==false) { return $inlined."h2,h1{color:red !important;}"; } else { return $inlined; } }
While it works, it is adding at the end of the existing global critical CSS that I put in the plugin settings. I can delete the whole global and do this per page, but I would like to have a backup critical CSS while I go fixing page by page the CSS and also it would create FOUC until I get to those pages.
Also I was wondering if is possible to do this, how do I add more pages to that function without duplicating an entire function? I was thinking of using
elseif
per page.I appreciate the help as always, I am just not sure why it is not overriding it all per page.
Thanks in advance
- The topic ‘Using inline and defer API override global per page’ is closed to new replies.