wp如何自動(dòng)生成目錄

1. 使用插件插件推薦:Table of Contents by Jino Tu 安裝并激活該插件。 在文章編輯器中,勾選“自動(dòng)插入目錄”選項(xiàng)。 2. 使用短代碼```...
1. 使用插件
插件推薦:Table of Contents by Jino Tu
安裝并激活該插件。
在文章編輯器中,勾選“自動(dòng)插入目錄”選項(xiàng)。
2. 使用短代碼
```html
$heading = '目錄';
$tag = 'h2'; // 你可以根據(jù)需要修改為'h1', 'h3'等
$shortcode = '[toc ' . $heading . ' ' . $tag . ']';
echo do_shortcode($shortcode);
?>
```
3. 使用函數(shù)
```php
function custom_toc() {
echo '
目錄
- ';
- $1 ', $content); $content = preg_replace('/
- $1 ', $content);
- $1 ', $content);
$content = get_the_content();
$content = preg_replace('/
]>(.?)
/i', ']>(.?)
/i', '$content = preg_replace('/
]>(.?)
/i', 'echo $content;
echo '
本文由夕逆IT于2025-02-23發(fā)表在夕逆IT,如有疑問,請(qǐng)聯(lián)系我們。
本文鏈接:http:///bian/708620.html
本文鏈接:http:///bian/708620.html