My Divi Breadcrumbs module allows you to show users where they are in your Divi site – i.e. their location relative to your homepage. But what if you want breadcrumbs which show the user the last pages they've visited?
While there isn't yet a feature in the breadcrumbs module for doing this, I've just added a "filter" to the breadcrumbs module – available from version 1.2.3 onwards – which lets you modify the breadcrumbs programmatically. This means you can implement dynamic breadcrumbs with something like the following PHP code:
add_action('wp', 'dbbccf_record_page_visit_in_cookie');
add_filter('et_pb_dmb_breadcrumbs_crumbs', 'dbbccf_get_breadcrumbs_from_cookie');
function dbbccf_record_page_visit_in_cookie() {
global $post;
$breadcrumbs = dbbccf_get_breadcrumbs_from_cookie();
$title = get_the_title();
if (!empty($title)) {
$breadcrumbs[] = array(
'text' => $title,
'url' => get_permalink()
);
}
$breadcrumbs = array_slice($breadcrumbs, -5);
setcookie('dbbc_breadcrumbs', json_encode($breadcrumbs), 0, '/');
}
function dbbccf_get_breadcrumbs_from_cookie() {
$breadcrumbs = array();
if (isset($_COOKIE['dbbc_breadcrumbs'])) {
$breadcrumbs = json_decode(stripslashes($_COOKIE['dbbc_breadcrumbs']), true);
}
return $breadcrumbs;
}
Related Post: Adding PHP to the Divi Theme
Please note that this is a rough implementation for demonstration purposes. If you plan to use it, please test it thoroughly to ensure it does what you need. If you have any questions about it, please ask and I'll do my best to help out.
0 Comments