Tag: NMWA
404 — Fancy meeting you here!
Don't panic, we'll get through this together. Let's explore our options here.
//2025.10.26に追加、meta canonicalを追加する。 //2025.10.26 ttps://dev.ore-shika.com/post/wp-canonical/#i-2 //とりあえず現在のパーマリンクを取得 $canonical = get_permalink(); //アーカイブページの処理 //記事一覧ページはis_archiveが偽なのでis_homeでも評価 if ( is_home() || is_archive() ) { $canonical = home_url().'/'; //記事一覧ページがトップページ以外に設定されている場合 if ( is_home() && get_option('page_for_posts') ) { $canonical = get_permalink(get_option('page_for_posts')); } //カテゴリアーカイブの処理 if ( is_category() ) { $canonical = get_category_link($cat); } //タグアーカイブの処理 if ( is_tag() ) { $canonical = get_category_link($tag_id); } //タクソノミーアーカイブの処理 if ( is_tax() ) { $canonical = get_term_link($term, $taxonomy); } //投稿者アーカイブの処理 if ( is_author() ) { $canonical = get_author_posts_url($author); } //日付アーカイブの処理 if ( is_date() ) { $canonical = get_year_link($year); if ( $monthnum > 0 ) { $canonical = get_month_link($year, $monthnum); if ( $day > 0 ) { $canonical = get_day_link($year, $monthnum, $day); } } } //カスタム投稿タイプアーカイブの処理 if ( is_post_type_archive() ) { $canonical = get_post_type_archive_link($post_type); } //2ページ目以降もcanonicalに設定する場合の処理 //if ( $paged > 0 ) { // $canonical .= 'page/'.$paged.'/'; //} //固定ページと投稿ページの処理 } else if ( is_page() || is_single() ) { //URLはget_permalinkで取得済み //ページが分割されている場合の処理 //$pageが未定義エラー出る場合の対処を追加 if ( isset($page) && $page > 0 ) { $canonical .= $page.'/'; } } else if ( is_search() ) { //検索結果ページの処理 } else if ( is_404() ) { //404の場合の処理 } //404でなければcanonicalを出力 //404でも出力したい場合はifを削除 if ( !is_404() ) { print ''."\n"; }
Don't panic, we'll get through this together. Let's explore our options here.