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

kumamon

kumamon

Posted on March 12, 2020

【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; ?> 
💖 💪 🙅 🚩
kumamon
kumamon

Posted on March 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related