Blog スタッフブログ

WEB制作

【WORDPRESS】リダイレクトで指定したページに遷移する設定方法

こんにちは、WEB開発の米田です。

今回はWORDPRESSの投稿でアーカイブのみ使用した場合にシングルページなどに飛んだ際、コンテンツがないためすぐに投稿した状態が見れるようにリダイレクト設定をします。

シングルページを使わずアーカイブにリダイレクトしたいカテゴリー(例としてnews)を設定します

<?php
if(in_category('news') && !is_home() && !is_category('')){
  wp_safe_redirect( home_url('news') );
  exit;
}
?>

これでカテゴリーnewsのシングルページに入ったら、すぐにリダイレクトされアーカイブページに飛ぶことができます。

トップページにリダイレクトしたい場合は

<?php
if(in_category('news') && !is_home() && !is_category('')){
  wp_safe_redirect( home_url('') );
  exit;
}
?>

になります。


Warning: Undefined array key 0 in /home/fl0uhem6u4/mixltd.jp/public_html/cms/wp-content/themes/mix_theme/pagination-single.php on line 3

Warning: Attempt to read property "cat_ID" on null in /home/fl0uhem6u4/mixltd.jp/public_html/cms/wp-content/themes/mix_theme/pagination-single.php on line 3