@charset "UTF-8";

/*!
Theme Name: Cocoon Child
Description: Cocoon専用の子テーマ
Theme URI: https://wp-cocoon.com/
Author: わいひら
Author URI: https://nelog.jp/
Template:   cocoon-master
Version:    1.1.3
*/

/************************************
** 子テーマ用のスタイルを書く
************************************/
/*必要ならばここにコードを書く*/

/************************************
** レスポンシブデザイン用のメディアクエリ
************************************/
/*1023px以下*/
@media screen and (max-width: 1023px){
  /*必要ならばここにコードを書く*/
}

/*834px以下*/
@media screen and (max-width: 834px){
  /*必要ならばここにコードを書く*/
}

/*480px以下*/
@media screen and (max-width: 480px){
  /*必要ならばここにコードを書く*/
}
// 旧URLが 404 のとき、同スラッグの投稿へ 301 で転送（/movie-xxx/ 等）
add_action('template_redirect', function () {
  if ( ! is_404() ) return;
  $path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
  // 階層が1つだけ（/xxxx/ 形式）の旧URLだけ対象
  if ($path && substr_count($path, '/') === 0) {
    $slug = $path;
    // まず完全一致
    $post = get_page_by_path($slug, OBJECT, 'post');
    // だめなら末尾の -2 / -3 を外して再検索
    if ( ! $post && preg_match('/^(.*)-\d+$/', $slug, $m) ) {
      $post = get_page_by_path($m[1], OBJECT, 'post');
    }
    if ($post && $post->post_status === 'publish') {
      wp_redirect(get_permalink($post), 301);
      exit;
    }
  }
});
