如何在WordPress主題中新增自定義字型?

新增自定義字型可以使您的WordPress網站具有獨特的外觀和風格。以下是在WordPress主題中新增自定義字型的步驟:

上傳自定義字型檔案:將您想要使用的自定義字型檔案上傳到您的WordPress安裝目錄中的 wp-content/uploads 資料夾中。確保您具有合法的許可證來使用這些字型檔案。

新增自定義字型到CSS樣式表:在您的主題的CSS樣式表中新增對自定義字型的引用。使用正確的字型路徑和字型名稱,並將字型新增到適當的CSS選擇器中。例如:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@font-face {
font-family: 'MyCustomFont';
src: url('uploads/my-custom-font.woff2') format('woff2'),
url('uploads/my-custom-font.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face { font-family: 'MyCustomFont'; src: url('uploads/my-custom-font.woff2') format('woff2'), url('uploads/my-custom-font.woff') format('woff'); font-weight: normal; font-style: normal; }
@font-face {  
  font-family: 'MyCustomFont';  
  src: url('uploads/my-custom-font.woff2') format('woff2'),  
       url('uploads/my-custom-font.woff') format('woff');  
  font-weight: normal;  
  font-style: normal;  
}

應用自定義字型:在您的主題的CSS樣式表中,將自定義字型應用到所需的元素上。例如:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
body {
font-family: 'MyCustomFont', sans-serif;
}
body { font-family: 'MyCustomFont', sans-serif; }
body {  
  font-family: 'MyCustomFont', sans-serif;  
}

更新並測試主題:儲存您的更改,並更新您的WordPress主題。然後,通過訪問您的網站來測試自定義字型是否按預期顯示和應用。

更詳細的教學,可以參考“如何不使用任何外掛在WordPress中新增自定義字型?

未能解決您的問題?

請提交 聯絡工單