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

pha*_*eim 2 html css php wordpress fonts

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

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

包括标签.怎么修改?我在WordPress中使用正念主题(类似的),如果有人对这个页面的选项二进行了说明.

简要描述图像:

公司 - 网站标题

bir*_*ire 5

如何定位Twenty Twelve主题的博客标题中的特定单词?

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

/**
 * 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;
}
Run Code Online (Sandbox Code Playgroud)

我们使用bloginfo过滤器仅定位博客名称的第二个实例,从<body>标记开始计算.

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

h1.site-title span{
    color: red;
}
Run Code Online (Sandbox Code Playgroud)

例:

这是一个截图:

博客标题已修改

应该可以将我们的代码片段调整为其他主题.

我希望这有帮助.