Wood Chen

Add Breadcrumb Navigation to WordPress with Code, No Plugin Required

0 comments86 views24 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

1.Add a breadcrumb function to functions.php

// Breadcrumb navigation
function the_breadcrumb() {
echo '';
if (!is_home()) { // If this is not the homepage
echo '首页 > ';
if (is_category() || is_single()) { // If this is a category or post page
echo '';
the_category('  ');
if (is_single()) { // If this is a post page
echo " > ".get_the_title().'';
}
} elseif (is_page()) { // If this is a standalone page
echo ''.get_the_title().'';
}elseif(is_tag()){ // If this is a tag page
single_cat_title();
}elseif (is_author()) { // If this is an author page
echo"作者页面"; echo'';
}elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { // If this is a paginated page
echo "列表分页"; echo'';
}elseif (is_search()) { // If this is a search page
echo"搜索页"; echo'';
}elseif (is_day()) {
echo"日期归档(天) "; the_time('F jS, Y'); echo'';
}elseif (is_month()) {
echo"日期归档(月)r "; the_time('F, Y'); echo'';
}elseif (is_year()) {
echo"日期归档(年) "; the_time('Y'); echo'';
}
}
echo '';
}

2.Call it wherever you want breadcrumbs to appear, using neve or your theme's hooks

< div class="breadcrumb">

Last updated 2024-01-14

Related posts

Comments 0