-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathBreadcrumb.php
More file actions
76 lines (64 loc) · 1.89 KB
/
Breadcrumb.php
File metadata and controls
76 lines (64 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Breadcrumb a11y service
* https://www.wpexplorer.com/accessible-yoast-seo-breadcrumbs/
* https://developer.yoast.com/features/blocks/breadcrumbs/
* https://gist.github.com/doubleedesign/7224a5e990b8506ddb8ec66de8348b2b
*/
namespace BEA\Theme\Framework\Services;
use BEA\Theme\Framework\Service;
use BEA\Theme\Framework\Service_Container;
class Breadcrumb implements Service {
public function register( Service_Container $container ): void {
}
public function boot( Service_Container $container ): void {
add_filter( 'wpseo_breadcrumb_output_wrapper', [ $this, 'replace_breadcrumb_wrapper' ]);
add_filter( 'wpseo_breadcrumb_single_link_wrapper', [ $this, 'replace_breadcrumb_link_wrapper' ]);
add_filter( 'wpseo_breadcrumb_single_link', [ $this, 'replace_breadcrumb_link' ] );
add_filter( 'wpseo_breadcrumb_separator', [ $this, 'remove_breadcrumb_separator' ] );
}
/**
* Get service name
*
* @return string
*/
public function get_service_name(): string {
return 'breadcrumb';
}
/**
* Replace the wrapper around the breadcrumbs
*
* @return string
*/
public function replace_breadcrumb_wrapper(): string {
return 'ol';
}
/**
* Replace the wrappers around the links.
*
* @return string
*/
public function replace_breadcrumb_link_wrapper(): string {
return 'li';
}
/**
* Replace the links and add the separator inside with aria-hidden="true".
*
* @param string $link_output The link output.
* @return string
*/
public function replace_breadcrumb_link( $link_output ): string {
if ( ! str_contains( $link_output, 'breadcrumb_last' ) ) {
return str_replace( '</li>', '<span class="breadcrumb__separator" aria-hidden="true">></span></li>', $link_output );
}
return $link_output;
}
/**
* Remove the breadcrumbs separator outside the links.
*
* @return string
*/
public function remove_breadcrumb_separator(): string {
return '';
}
}