HOME > WordPress > 404ページとリダイレクト

404ページとリダイレクト

ページが存在しませんページ「404」ページ。WordPressで用意する方法。

シンプルな実装方法

  • テーマファイルは404.php
  • header.phpに下記、自動リダイレクト処理を記述

jsではなくmetaタグで用意するリダイレクト

<?php if( is_404()) : ?>
<meta http-equiv="refresh" content="5; URL=<?php echo do_shortcode('[url]'); ?>">
<?php endif; ?>

content=”5;のところが、リダイレクトまでの秒数。
URL=<?php echo do_shortcode(‘https://lib.ridesign.jp‘)?>”>は移線先。この場合、トップページに移線させている。

移線先や何秒後にリダイレクトするかは、404.phpで明記するとユーザーに分かりやすい。

参考サイト

    Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/libridesign2017/single-post.php on line 54

Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/ridesignjp2016/relatedLinks.php on line 10