DEV Community

kumamon
kumamon

Posted on

1 2

【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)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay