wp_list_categories如何去掉前面的categories
- 2019 年 10 月 6 日
- 筆記
我們可以通過<?php wp_list_categories(); ?>來調用所有分類,但是在前面會出現一個categories,對強迫症患者來說就是釘子,那就把它去掉吧,順便讓自己更熟悉wordpress機制,怎麼刪除呢?隨ytkah一起來看看

1、首先我們要先確定wp_list_categories在哪裡定義,通過https://developer.wordpress.org/reference/functions/wp_list_categories/我們查到了具體的文件位置wp-includes/category-template.php
2、備份文件,然後打開文件,我們需要先知道$title_li的作用,這個就是定義標題Categories的地方。然後我們找到大概在536行,把Categories換成空格,英文狀態下的空格,直接刪除的話可能樣式會變了。
Text to use for the list title `<li>` element. Pass an empty string to disable. Default 'Categories'.

3、保存上傳替換文件,更新緩存,刷新頁面,是不是已經沒有了?
感興趣的朋友可以試試!有疑問可以加ytkah諮詢