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.

Revisions

  1. ygnthetzaw created this gist Apr 4, 2022.
    21 changes: 21 additions & 0 deletions breadcrumb.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?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>';
    }

    ?>