-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyoast.php
76 lines (66 loc) · 2.2 KB
/
yoast.php
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
/*
Plugin Name: Yoast Helpers
Description: Pagination meta override
Author: Zorca, Dima Minka, CDK
Version: 1.0
Author URI: https://dima.mk
*/
/** Add Page Number to Title and Meta Description for SEO **/
if (!function_exists('multipage_metadesc')) {
function multipage_metadesc($s)
{
global $page;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
!empty($page) && 1 < $page && $paged = $page;
$site_title = !$s ? get_bloginfo() . ' ' : '';
$paged > 1 && $s = $site_title . $s . ' - ' . sprintf(__('Page %s'), $paged);
return $s;
}
add_filter('wpseo_metadesc', 'multipage_metadesc', 100, 1);
}
if (!function_exists('multipage_title')) {
function multipage_title($title)
{
global $page;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
!empty($page) && 1 < $page && $paged = $page;
$paged > 1 && $title .= ' - ' . sprintf(__('Page %s'), $paged);
return $title;
}
add_filter('wpseo_title', 'multipage_title', 100, 1);
}
/** Make the last item of breadcrumbs a link */
if ( ! function_exists( 'wpseo_convert_current_page_to_link' ) ) {
/**
* @param $link_output
* @param $link
*
* @return string|string[]|null
*/
function wpseo_convert_current_page_to_link( $link_output, $link ) {
$result = $link_output;
if ( stripos( $link_output, 'breadcrumb_last' ) !== false ) {
$a_attributes = [
'href' => esc_url( $link['url'] ),
'class' => 'breadcrumb_last',
'aria-current' => 'page',
];
if ( isset( $link['title'] ) ) {
$a_attributes['title'] = esc_attr( $link['title'] );
}
$a_atr_str = '';
foreach ( $a_attributes as $attr_name => $attr_value ) {
$a_atr_str .= " $attr_name=\"$attr_value\"";
}
$link = "<a$a_atr_str>{$link['text']}</a>";
$wrapper = WPSEO_Options::get( 'breadcrumbs-boldlast' ) === true ? 'strong' : 'span';
$preg_result = preg_replace( "/<$wrapper.*>.+<\/$wrapper>/U", $link, $link_output );
if ( ! empty( $preg_result ) ) {
$result = $preg_result;
}
}
return $result;
}
add_filter( 'wpseo_breadcrumb_single_link', 'wpseo_convert_current_page_to_link', 10, 2 );
}