如何使用Breadcrumb NavXT修改WordPress面包屑最后一项名称
Looks like you're using Breadcrumb NavXT, and your breadcrumb is stuck showing "Detail Post New" instead of the actual post title on your single post display page. Here are two reliable ways to fix this:
Method 1: Use Breadcrumb NavXT's Filter Hook (Recommended)
This is the cleanest approach, leveraging the plugin's built-in filters to modify the breadcrumb title directly. Add this code to your theme's functions.php file (or a custom plugin):
add_filter('bcn_breadcrumb_title', 'swap_detail_post_with_post_title', 10, 3); function swap_detail_post_with_post_title($title, $type, $id) { // Check if we're on a single post and the breadcrumb title is the fixed text if (is_singular('post') && $title === 'Detail Post New') { // Return the current post's title instead return get_the_title(); } // Keep the original title for other cases return $title; }
How this works:
- The
bcn_breadcrumb_titlefilter lets you modify individual breadcrumb titles before they're rendered. - We check if we're on a single post page (
is_singular('post')) and if the current title matches your fixed "Detail Post New" text. - If both conditions are met, we replace it with the actual post title using
get_the_title().
Method 2: Modify the Output Directly (Brute-Force Alternative)
If for some reason the filter hook doesn't work (e.g., older plugin version), you can capture and edit the HTML output of bcn_display() directly. Update your existing breadcrumb code to this:
<nav aria-label="breadcrumb" class="wrap-breadcrumb"> <div class="container"> <div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/"> <?php if(function_exists('bcn_display')) { // Capture the breadcrumb HTML output ob_start(); bcn_display(); $breadcrumb_output = ob_get_clean(); // Replace the fixed text with post title if on a single post if (is_singular('post')) { $post_title = get_the_title(); $breadcrumb_output = str_replace('Detail Post New', $post_title, $breadcrumb_output); } // Print the modified breadcrumb echo $breadcrumb_output; } ?> </div> </div> </nav>
Note:
Method 1 is preferred because it's more maintainable—string replacement (Method 2) can break if the plugin changes how it outputs HTML or if the fixed text has any surrounding HTML.
内容的提问来源于stack exchange,提问作者Khả Nam

