简体   繁体   English

如何在 WordPress (Moderne) 的网站标题中显示单独的颜色?

[英]How to display separate colours in site title on WordPress (Moderne)?

I have a WordPress site that is running the Moderne theme - https://wordpress.org/themes/moderne/ .我有一个运行现代主题的 WordPress 网站 - https://wordpress.org/themes/moderne/

It's definitely my favourite so far and really matches what I want my site to be.到目前为止,它绝对是我最喜欢的,并且真正符合我希望我的网站成为的样子。 But what I'm struggling to figure out is how to change my site title so that I can have separate colours, to match my logo, which is white-yellow-white.但我正在努力弄清楚如何更改我的网站标题,以便我可以有不同的颜色,以匹配我的徽标,即白-黄-白。

I know that I can edit the colours itself through style.css, but I just can't seem to figure out how to separate out the sections.我知道我可以通过 style.css 编辑颜色本身,但我似乎无法弄清楚如何分开这些部分。

This is my site: http://nobetterdan.com/ .这是我的网站: http://nobetterdan.com/

Ideally, what I want to try and do is -理想情况下,我想尝试做的是 -

  • no in white没有白色
  • betterdan in yellow黄色的贝特丹
  • the full stop at the end in white结尾处的句号为白色

It's probably super easy, but just not sure.这可能非常简单,但不确定。

This can be accomplished via javascript.这可以通过 javascript 完成。

 var _title = document.querySelector("#site-title a"); _title.innerHTML = _title.innerHTML.replace("no","<span class='logo-white'>no</span>").replace("betterdan","<span class='logo-yellow'>betterdan</span>").replace(".","<span class='logo-white'>.</span>");
 body{background:#000}.logo-yellow{color:yellow}.logo-white{color:white}
 <h1 id="site-title"><a href="http://nobetterdan.com/" rel="home">nobetterdan.</a></h1>

This is a little more complex than it seems, because in CSS, you can only target the first letter but the not each individual letter inside a word:这比看起来要复杂一点,因为在 CSS 中,您只能定位第一个字母,而不是单词中的每个字母:

h1::first-letter {}

https://www.w3schools.com/cssref/sel_firstletter.asp https://www.w3schools.com/cssref/sel_firstletter.asp

You have to seperate the page title to the units you want to have (header.php in the folder of your theme):您必须将页面标题与您想要的单位分开(主题文件夹中的 header.php):

<h1 id="site-title">
    <a href="<?php echo get_home_url(); ?>" rel="home">no<span class="yellow">betterdan</span>.</a>
</h1>

So you can target this characters in your CSS:所以你可以在你的 CSS 中定位这些字符:

.site-title { color: white; }
.yellow { color: yellow; }

This way you cannot make use you the <?php echo get_the_title(); ?>这样你就不能使用<?php echo get_the_title(); ?> <?php echo get_the_title(); ?> function in the header.php of your theme. <?php echo get_the_title(); ?> function 在您的主题的 header.php 中。 But if it is a ok for you to write the title with no dynamic value, you can simply adjust this in the file that contains your h1 tag.但是如果您可以编写没有动态值的标题,您可以在包含 h1 标签的文件中简单地调整它。

Important : You are using a theme, which can have updates sometimes.重要提示:您使用的主题有时会更新。 Keeping this up to date is important, so if you are doing changes in your theme files, make sure to have a child theme running, so your parent theme files are overwritten and can be update when needed.保持最新是很重要的,所以如果您正在对主题文件进行更改,请确保有一个子主题正在运行,这样您的父主题文件就会被覆盖,并且可以在需要时进行更新。 This is a nice and easy tutorial for creating a child theme: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/这是一个用于创建子主题的简单易用的教程: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/


Another way would be to use javascript for the coloring of your headline.另一种方法是使用 javascript 为标题着色。 There also is a jquery plugin for this: http://letteringjs.com/ But I think for this single use case, for styling the title of your page, this would be an overload and much code you actually don't need.为此还有一个 jquery 插件: http://letteringjs.com/但我认为对于这个单一的用例,为了设置页面标题的样式,这将是一个过载和许多您实际上不需要的代码。 So the way using the span and css would be the more appropriate way.所以使用 span 和 css 的方式将是更合适的方式。

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

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