简体   繁体   English

在wordpress中仅更改一页(联系我们)中的CSS

[英]Changing CSS in only one page (the contact us) in wordpress

I made a website based on wordpress for a client. 我为客户建立了一个基于wordpress的网站。 But the client is very strange, he want to have different design for the Contact Us page than other pages. 但是客户很奇怪,他希望“联系我们”页面的设计与其他页面不同。

I made a CSS for Contact Us page, but if I add that CSS to the style.css in the theme directory, it will override the CSS (colors) for the rest of the pages too, but I want to change the CSS only for the Contact Us page. 我制作了一个CSS for Contact Us页面,但是如果将CSS添加到主题目录中的style.css中,它也会覆盖其余页面的CSS(颜色),但是我只想更改CSS联系我们页面。

The problem is that the pages we create in the Wordpress are not physical pages like in a static website, if that was the case i would add internal or inline CSS, but that doesn't work in my case. 问题是我们在Wordpress中创建的页面不是像静态网站中那样的物理页面,如果是这种情况,我会添加内部或内联CSS,但在我的情况下不起作用。

Thank you all in Advance. 谢谢大家。

The wp_enqueue_style can save you here. wp_enqueue_style可以将您保存在这里。 The description for this wordpress function is, A safe way to add/enqueue a CSS style file to the wordpress generated page (in your case, its a wordpress generated page). 此wordpress函数的描述是,一种将CSS样式文件添加/排队到wordpress生成的页面(在您的情况下,它是wordpress生成的页面)的安全方法。

Use it as follows. 如下使用。

add_action( 'wp_enqueue_scripts', 'addCustomCSS');
function addCustomCSS()
{
    if(is_page(your_page_title_goes_here))
    {
        wp_enqueue_style( 'link_to_your_custom_stylesheet_goes_here' );
    }
}

Check if the page already has some different class for body 检查页面是否已经有不同的body

so if you have 所以如果你有

<body class="page contact">

then you can use 那么你可以使用

body.contact h1{
display:none;
}

If you have a large amount of changes, it would be better you tweak the setting to include custom css for a page. 如果您进行了大量更改,最好调整设置以包括页面的自定义CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM