DEV Community

kumamon
kumamon

Posted on

【WordPress】ページネーションがあるページのnoindex,canonical対応

<?php
$url = $_SERVER['REQUEST_URI'];
if(strstr($url,'/page/')==true):
?>
<meta name="robots" content="noindex,follow">
 <?php
      $cat = get_the_category();
      $cat_id = $cat[0]->cat_ID;
      $link = get_category_link($cat_id);
    ?>  
<link rel="canonical" href="<?php echo $link; ?>">

<?php else: ?>
<link rel="canonical" href="<?=home_url().$_SERVER["REQUEST_URI"]; ?>">
<?php endif; ?> 

Top comments (0)