function generate_custom_slug_thai($post_title) { preg_match('/\b(20\d{2})\b/', $post_title, $matches); $year = isset($matches[1]) ? $matches[1] : date('Y'); $slug = sanitize_title($post_title); // ถ้ามีปีอยู่แล้วใน slug → ไม่เติมปีซ้ำ if (preg_match('/20\d{2}/', $slug)) { return $slug; } return $slug . '-' . $year; }