簡體   English   中英

用兩種不同的顏色設置WordPress頁面的標題

[英]Set title of the WordPress page with two different colors

我的WordPress中的標題是兩個字(例如,“公司”)。 現在,默認顏色是藍色。 但我希望以上示例中的“ The”部分為灰色。 我使用了字體標簽,並在站點標題“輸入”框中將其設置為<font color="grey">The</font> Company 在預覽頁面中,它顯示正確,但是當我訪問頁面時,它顯示為

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

包括標簽。 怎么修改? 如果有人對本頁面的第二個選項有所了解,我將在WordPress(類似類型)中使用正念主題。

簡要描述的圖片:

公司-網站標題

如何針對二十二十二主題的博客標題中的特定單詞?

您可以嘗試以下方法,它適用於“ 十二十二”主題:

/**
 * 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過濾器僅定位博客名稱的第二個實例,該實例從<body>標記開始計數。

然后,我們可以使用CSS定位span標簽:

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

例:

這是屏幕截圖:

博客標題已修改

也可以將我們的代碼段也調整為其他主題。

我希望這有幫助。

為此,您必須更改控制設計的style.css。 主題。

從wordpress編輯CSS:

登錄到WordPress,不確定所運行的版本,但是應該有一個名為“主題或設計”的部分。 從那里選擇主題編輯器。 將列出所有可以編輯的文件,CSS樣式表應命名為style.css。

您必須具有寫權限才能在WP admin中進行編輯。

否則,您將必須通過FTP在您的網站上找到文件,將其下載到計算機上,進行編輯,然后再將其上傳回您的站點。

按照您想要的方式編輯CSS:

<span id="the">The</span>
<span id="company">Company</span>
<style>

#the{color: #0033CC;} //refers to blue.
#company{color:#CCCCCC;} //refers to grey.

</style>

還有一個小提琴供您測試:

JSFIDDLE演示

祝好運!

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM