Created
December 10, 2019 04:01
-
-
Save mhige/1d323edd223881621b4f3240a5209ad8 to your computer and use it in GitHub Desktop.
AMPを表示したいページとしたくないページを切り分ける例(コメントなし)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function amp_link_tag(){ | |
$content = apply_filters('the_content', get_post_field('post_content', get_the_ID())); | |
$no_amp_a8ad = preg_match('/<a.*?href="https:\/\/px\.a8\.net/is', $content); | |
if(is_singular('post') && is_mobile() && !$no_amp_a8ad){ | |
$amp_param = '?amp=1'; | |
echo '<link rel="amphtml" href="'.esc_url(get_permalink()).$amp_param.'">'."\n"; | |
} | |
} | |
add_action('wp_head','amp_link_tag'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment