Skip to content

Instantly share code, notes, and snippets.

@novrian
Last active March 14, 2019 16:09
Show Gist options
  • Select an option

  • Save novrian/6106081 to your computer and use it in GitHub Desktop.

Select an option

Save novrian/6106081 to your computer and use it in GitHub Desktop.
Yoast Breadcrumb with Twitter Bootstrap Markup
<?php
/**
* Yoast Breadcrumbs on Twitter Bootstrap
*
* @author Novrian <me@novrian.info>
* @copyright (c) 2013. Novrian Y.F.
* @license MIT License
* @param string $sep Your custom separator
*/
function novrian_breadcrumbs($sep = '/') {
if (!function_exists('yoast_breadcrumb')) {
return null;
}
// Default Yoast Breadcrumbs Separator
$old_sep = '\&raquo\;';
// Get the crumbs
$crumbs = yoast_breadcrumb(null, null, false);
// Hilangkan wrapper <span xmlns:v />
$output = preg_replace("/^\<span xmlns\:v=\"http\:\/\/rdf\.data\-vocabulary\.org\/#\"\>/", "", $crumbs);
$output = preg_replace("/\<\/span\>$/", "", $output);
// Ambil Crumbs
$crumb = preg_split("/\40(" . $old_sep . ")\40/", $output);
// Manipulasi string output tiap crumbs
$crumb = array_map(
create_function('$crumb', '
if (preg_match(\'/\<span\40class=\"breadcrumb_last\"/\', $crumb)) {
return \'<li class="active">\' . $crumb . \'</li>\';
}
return \'<li>\' . $crumb . \' <span class="divider">' . $sep . '</span></li>\';
'),
$crumb
);
// Bangun output HTML
$output = '<div class="breadcrumbs-container" xmlns:v="http://rdf.data-vocabulary.org/#"\><ul class="breadcrumb">' . implode("", $crumb) . '</ul></div>';
// Print
echo $output;
}
@khoipro

khoipro commented Dec 22, 2015

Copy link
Copy Markdown

Hi novrian,

How to include this path to theme correct?

Thank you,

ghost commented Aug 10, 2016

Copy link
Copy Markdown

This doesn't provide a valid HTML output, and puts everything underneath a single span. How does this use the Bootstrap format at all? http://getbootstrap.com/components/#breadcrumbs

@jarrodagims

Copy link
Copy Markdown

This is bad. all it does is wrap the breadcrumbs in a single list item. which you can do without any plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment