方法 1:放在 header.php(推荐)
适用场景:在所有页面的头部下方显示面包屑
具体位置:WordPress 后台 → 外观 → 主题文件编辑器 → 右侧选择 header.php
添加步骤:
- 在
header.php中找到</header>标签 - 在
</header>后面添加以下代码 - 点击"更新文件"
完整代码示例:
</header>
<?php if (!is_front_page()): // 首页不显示面包屑 ?>
<div class="breadcrumb-wrapper" style="padding: 15px 0; background: #f5f5f5;">
<div class="container">
<?php if (function_exists('nx_seo_breadcrumb')) nx_seo_breadcrumb(); ?>
</div>
</div>
<?php endif; ?>
<main class="site-content">
方法 2:只在文章页显示
位置:外观 → 主题文件编辑器 → single.php
<?php get_header(); ?>
<div class="container" style="padding: 15px 0;">
<?php if (function_exists('nx_seo_breadcrumb')) nx_seo_breadcrumb(); ?>
</div>
<article>
<?php the_content(); ?>
</article>
方法 3:使用短代码(最灵活)
适合页面构建器(Elementor、Divi 等)或想手动控制位置
[nx_seo_breadcrumb]
在编辑文章/页面时,在想显示面包屑的位置添加此短代码即可