I have a wordpress website which I am coverting to an AMP website for now I am using the amp plugin Now my website has a lot of css files and the style that I can inline is limited so I am trying to add a custom css using :
<style amp-custom>
.someclass={/*my custom css I want it to affect only amp pages*/}
</style>
I can add the style without problem to all pages by adding it to the header.php file, Now The thing is I want this tyle to be applied only to my amp pages , they have a special urls (Adding ?amp at the end).
www.mywebsite.com : is my website
www.mywebsite.com?amp is the amp page for my website, I am overriding the css by adding these inline custom css to affect these pages.
can I make it so that the custom css is only applied to the amp pages ?
You can use amp_post_template_css
action if you are using this plugin.
function custom_post_template_css() {
?>
.someclass={
/*my custom css I want it to affect only amp pages*/
}
<?php
}
add_action( 'amp_post_template_css','custom_post_template_css', 11 );
Please refer to the Custom CSS for the documentation.