@@ -64,27 +64,31 @@ public function register() {
64
64
add_filter ( 'amp_default_options ' , [ $ this , 'filter_default_options ' ] );
65
65
add_filter ( 'amp_options_updating ' , [ $ this , 'sanitize_options ' ], 10 , 2 );
66
66
67
- $ is_mobile_redirect_enabled = AMP_Options_Manager::get_option ( Option::MOBILE_REDIRECT );
68
- $ sandboxing_level = amp_get_sandboxing_level ();
67
+ if ( ! amp_is_canonical () ) {
68
+ $ sandboxing_level = amp_get_sandboxing_level ();
69
+ $ is_mobile_redirect_enabled = AMP_Options_Manager::get_option ( Option::MOBILE_REDIRECT );
69
70
70
- // Add alternative link if mobile redirection is enabled or sandboxing level is set to loose or moderate.
71
- if ( ! amp_is_canonical () && ( $ is_mobile_redirect_enabled || ( 1 === $ sandboxing_level || 2 === $ sandboxing_level ) ) ) {
72
- add_action ( 'wp_head ' , [ $ this , 'add_mobile_alternative_link ' ] );
73
- }
71
+ // Add alternative link if mobile redirection is enabled or sandboxing level is set to loose or moderate.
72
+ if ( $ is_mobile_redirect_enabled || ( 1 === $ sandboxing_level || 2 === $ sandboxing_level ) ) {
73
+ add_action ( 'wp_head ' , [ $ this , 'add_mobile_alternative_link ' ] );
74
+ }
74
75
75
- if ( $ is_mobile_redirect_enabled && ! amp_is_canonical () ) {
76
- add_action ( 'template_redirect ' , [ $ this , 'redirect ' ], PHP_INT_MAX );
76
+ if ( ! $ is_mobile_redirect_enabled ) {
77
+ add_action ( 'template_redirect ' , [ $ this , 'maybe_add_mobile_switcher_link ' ], PHP_INT_MAX );
78
+ } else {
79
+ add_action ( 'template_redirect ' , [ $ this , 'redirect ' ], PHP_INT_MAX );
77
80
78
- // Enable AMP-to-AMP linking by default to avoid redirecting to AMP version when navigating.
79
- // A low priority is used so that sites can continue overriding this if they have done so.
80
- add_filter ( 'amp_to_amp_linking_enabled ' , '__return_true ' , 0 );
81
+ // Enable AMP-to-AMP linking by default to avoid redirecting to AMP version when navigating.
82
+ // A low priority is used so that sites can continue overriding this if they have done so.
83
+ add_filter ( 'amp_to_amp_linking_enabled ' , '__return_true ' , 0 );
81
84
82
- add_filter ( 'comment_post_redirect ' , [ $ this , 'filter_comment_post_redirect ' ] );
85
+ add_filter ( 'comment_post_redirect ' , [ $ this , 'filter_comment_post_redirect ' ] );
83
86
84
- // Amend the comments/respond links to go to non-AMP page when in legacy Reader mode.
85
- if ( amp_is_legacy () ) {
86
- add_filter ( 'get_comments_link ' , [ $ this , 'add_noamp_mobile_query_var ' ] ); // For get_comments_link().
87
- add_filter ( 'respond_link ' , [ $ this , 'add_noamp_mobile_query_var ' ] ); // For comments_popup_link().
87
+ // Amend the comments/respond links to go to non-AMP page when in legacy Reader mode.
88
+ if ( amp_is_legacy () ) {
89
+ add_filter ( 'get_comments_link ' , [ $ this , 'add_noamp_mobile_query_var ' ] ); // For get_comments_link().
90
+ add_filter ( 'respond_link ' , [ $ this , 'add_noamp_mobile_query_var ' ] ); // For comments_popup_link().
91
+ }
88
92
}
89
93
}
90
94
}
@@ -184,6 +188,16 @@ public function redirect() {
184
188
}
185
189
}
186
190
191
+ /**
192
+ * Add mobile switcher link in footer when serving an AMP page.
193
+ */
194
+ public function maybe_add_mobile_switcher_link () {
195
+ if ( amp_is_request () ) {
196
+ $ this ->add_mobile_switcher_head_hooks ();
197
+ $ this ->add_mobile_switcher_footer_hooks ();
198
+ }
199
+ }
200
+
187
201
/**
188
202
* Add mobile version switcher head hooks.
189
203
*/
0 commit comments