Skip to content

Instantly share code, notes, and snippets.

@mhige
Created December 10, 2019 04:01
Show Gist options
  • Save mhige/1d323edd223881621b4f3240a5209ad8 to your computer and use it in GitHub Desktop.
Save mhige/1d323edd223881621b4f3240a5209ad8 to your computer and use it in GitHub Desktop.
AMPを表示したいページとしたくないページを切り分ける例(コメントなし)
<?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