如何仅将自定义 css 样式应用于 Amp 页面 [英] How do I apply custom css styles only to Amp pages

查看:32
本文介绍了如何仅将自定义 css 样式应用于 Amp 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 wordpress 网站,现在我正在将其转换为 AMP 网站我正在使用 amp 插件现在我的网站有很多 css 文件,我可以内联的样式有限,所以我尝试使用以下方法添加自定义 css:

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>

通过将样式添加到 header.php 文件,我可以毫无问题地将样式添加到所有页面,现在问题是我希望此样式仅应用于我的 amp 页面,它们有一个特殊的 url(在结束).

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:是我的网站

  • www.mywebsite.com : is my website

www.mywebsite.com?amp 是我网站的 amp 页面,我通过添加这些内联自定义 css 来影响这些页面来覆盖 css.

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.

我可以让自定义 css 只应用于 amp 页面吗?

推荐答案

如果您正在使用 这个插件.

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 );

请参阅自定义 CSS用于文档.

这篇关于如何仅将自定义 css 样式应用于 Amp 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆