This repository has been archived by the owner on Oct 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
template-functions.php
112 lines (102 loc) · 2.72 KB
/
template-functions.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package AMPConf
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array Classes.
*/
function ampconf_body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'ampconf_body_classes' );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function ampconf_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'ampconf_pingback_header' );
/**
* Filters the string displayed after the excerpt.
*
* @return string $more_string More text.
*/
function ampconf_excerpt_more() {
return '…';
}
add_filter( 'excerpt_more', 'ampconf_excerpt_more' );
/**
* Filters the archive title and wraps the type of archive in a span element.
*
* @param string $title Archive title to be displayed.
* @return string $title Title.
*/
function ampconf_get_the_archive_title( $title ) {
$parts = explode( ':', $title );
if ( 2 <= count( $parts ) ) {
$title = str_replace( $parts[0] . ': ', '', $title );
$title = wp_kses(
sprintf(
'<span>%1$s</span>%2$s',
$parts[0],
$title
),
array(
'span' => array(),
)
);
}
return $title;
}
add_filter( 'get_the_archive_title', 'ampconf_get_the_archive_title' );
/**
* Filter the featured image for AMP.
*
* There is a problem with the AMP sanitizer that is not properly converting img into amp-img,
* so this is a workaround to preempt the sanitizer.
*
* @see get_the_post_thumbnail()
*
* @param string $html The post thumbnail HTML.
* @return string Amplified HTML.
*/
function ampconf_filter_post_thumbnail_html( $html ) {
if ( is_amp_endpoint() ) {
$html = str_replace( '<img ', '<amp-img ', $html ) . '</amp-img>';
}
return $html;
}
if ( function_exists( 'is_amp_endpoint' ) ) {
add_filter( 'post_thumbnail_html', 'ampconf_filter_post_thumbnail_html' );
}
/**
* Filter the custom logo image for AMP.
*
* There is a problem with the AMP sanitizer that is not properly converting img into amp-img,
* so this is a workaround to preempt the sanitizer.
*
* @see get_custom_logo()
*
* @param string $html The custom logo HTML.
* @return string Amplified HTML.
*/
function ampconf_filter_get_custom_logo( $html ) {
if ( is_amp_endpoint() ) {
$html = str_replace( '<img ', '<amp-img ', $html ) . '</amp-img>';
}
return $html;
}
if ( function_exists( 'is_amp_endpoint' ) ) {
add_filter( 'get_custom_logo', 'ampconf_filter_get_custom_logo' );
}