Amp.php
1.13 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
<?php
namespace AIOSEO\Plugin\Common\Meta;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Adds support for Google AMP.
*
* @since 4.0.0
*/
class Amp {
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
add_action( 'init', [ $this, 'runAmp' ] );
}
/**
* Run the AMP hooks.
*
* @since 4.0.0
*
* @return void
*/
public function runAmp() {
if ( is_admin() || wp_doing_ajax() || wp_doing_cron() ) {
return;
}
// Add social meta to AMP plugin.
$enableAmp = apply_filters( 'aioseo_enable_amp_social_meta', true );
if ( $enableAmp ) {
$useSchema = apply_filters( 'aioseo_amp_schema', true );
if ( $useSchema ) {
add_action( 'amp_post_template_head', [ $this, 'removeHooksAmpSchema' ], 9 );
}
add_action( 'amp_post_template_head', [ aioseo()->head, 'output' ], 11 );
}
}
/**
* Remove Hooks with AMP's Schema.
*
* @since 4.0.0
*
* @return void
*/
public function removeHooksAmpSchema() {
// Remove AMP Schema hook used for outputting data.
remove_action( 'amp_post_template_head', 'amp_print_schemaorg_metadata' );
}
}