Skip to content

Instantly share code, notes, and snippets.

@ygnthetzaw
Created April 4, 2022 19:36
Show Gist options
  • Save ygnthetzaw/04a39790f9503e9d6ecc687c5ecb090b to your computer and use it in GitHub Desktop.
Save ygnthetzaw/04a39790f9503e9d6ecc687c5ecb090b to your computer and use it in GitHub Desktop.
Simple Wordpress Breadcrumb based on current url
<?php
global $wp;
$route = home_url($wp->request);
$routeArray = explode('/', $route);
if (!empty($routeArray)) {
$breadcrumb = '<ol class="breadcrumb">';
$link = '';
for ($i = 0; $i < count($routeArray); $i++) {
$link .= $routeArray[$i] . '/';
if ($i >= 2) {
if ($i == 2) {
$breadcrumb .= '<li class="breadcrumb-item"><a href="' . $link . '">Home</a></li>';
} else {
$breadcrumb .= '<li class="breadcrumb-item"><a href="' . $link . '">' . $routeArray[$i] . '</a></li>';
}
}
}
$breadcrumb .= '</ol>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment