gpt4 book ai didi

php - 用两种不同的颜色设置 WordPress 页面的标题

转载 作者:太空宇宙 更新时间:2023-11-04 14:36:36 25 4
gpt4 key购买 nike

我的 WordPress 中的标题是两个词(例如“The Company”)。现在默认颜色是蓝色。但是我希望上面例子中的“The”部分是灰色的。我使用了字体标签并将其设置为 <font color="grey">The</font> Company 在站点标题输入框中。在预览页面中它显示正确,但是当我访问我的页面时,它显示为

<font color="grey">The</font> Company

包括标签。如何修改?我在 WordPress 中使用正念主题(类似的)如果有人了解 this page 的选项二.

简要描述图像:

The Company - site title

最佳答案

如何定位22主题博客标题中的特定词?

您可以尝试以下方法,它适用于22 主题:

/**
* Wrap the first word of the blog title with the <span>...</span> tag.
* Assumes the Twenty Twelve theme.
*
* @see http://stackoverflow.com/a/25096093/2078474
*/

add_filter( 'body_class',
function( $class )
{
add_filter( 'bloginfo', 'so_25094932_modify_first_word', 10, 2 );
return $class;
}
);

function so_25094932_modify_first_word( $output, $show )
{
static $counter = 0;

// Target the "name" part:
if( 'name' === $show )
{
// Target the second instance:
if( 2 === ++$counter )
{
remove_filter( current_filter(), __FUNCTION__ );

// Modify the first word of the blog title:
$title = explode( ' ', $output );
if( count( $title ) > 0 )
{
$title[0] = sprintf( '<span>%s</span>', $title[0] );
}
$output = join( ' ', $title );
}
}
return $output;
}

我们在哪里使用 bloginfo过滤以仅针对博客名称的 second 实例,从 <body> 开始计算标签。

然后我们可以使用 CSS 定位 span 标签:

h1.site-title span{
color: red;
}

示例:

截图如下:

Blog title modified

应该也可以调整我们的代码片段以适应其他主题。

希望对您有所帮助。

关于php - 用两种不同的颜色设置 WordPress 页面的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25094932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com