Instantly share code, notes, and snippets.
alfiosalanitri/bootstrap4-yoast-seo-breadcrumb.php
Last active Dec 5, 2019
Bootstrap 4 Breadcrumb Markup for Yoast SEO Breadcrumb
/*************************************** | |
* Add this code to theme functions.php | |
***************************************/ | |
/** | |
* @param $wrapper | |
* | |
* @return string | |
*/ | |
function customWpseoBreadcrumbOutputWrapper($wrapper) | |
{ | |
return 'ol'; | |
} | |
add_filter('wpseo_breadcrumb_output_wrapper', 'customWpseoBreadcrumbOutputWrapper', 10, 1); | |
/** | |
* @param $class | |
* | |
* @return string | |
*/ | |
function customWpseoBreadcrumbOutputClass($class) | |
{ | |
return 'breadcrumb'; | |
} | |
add_filter('wpseo_breadcrumb_output_class', 'customWpseoBreadcrumbOutputClass', 10, 1); | |
/** | |
* @param $separator | |
* | |
* @return string | |
*/ | |
function customWpseoBreadcrumbSeparator($separator) | |
{ | |
return ''; | |
} | |
add_filter('wpseo_breadcrumb_separator', 'customWpseoBreadcrumbSeparator', 10, 1); | |
/** | |
* @param $wrapper | |
* | |
* @return string | |
*/ | |
function customWpseoBreadcrumbSingleLinkWrapper($wrapper) { | |
return 'li'; | |
} | |
add_filter('wpseo_breadcrumb_single_link_wrapper', 'customWpseoBreadcrumbSingleLinkWrapper', 10, 1); | |
/** | |
* @param $link_output | |
* @param $link | |
* | |
* @return string|string[] | |
*/ | |
function customWpseoBreadcrumbSingleLink($link_output, $link) | |
{ | |
return str_replace( | |
array( | |
'<li>', | |
'<span class="breadcrumb_last" aria-current="page">', | |
'</span>' | |
), | |
array( | |
'<li class="breadcrumb-item">', | |
'</li><li class="breadcrumb-item active" aria-current="page">', | |
'</li>' | |
), | |
$link_output); | |
} | |
add_filter('wpseo_breadcrumb_single_link', 'customWpseoBreadcrumbSingleLink', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment