ÿþ<?php /** * TedorentCar - Astra Child Theme functions.php * WhatsApp button handled by mu-plugin (whatsapp-button.php) * This file only contains theme-specific customizations. */ // Remove duplicate WhatsApp button from child theme (now handled by mu-plugin) // Keep only the URL tracking for analytics add_action('wp_footer', function() { ?> <script> (function() { // URL tracking for all WA links var currentUrl = window.location.href; var currentTitle = document.title; var waLinks = document.querySelectorAll('a[href*="wa.me"]'); waLinks.forEach(function(link) { var originalHref = link.getAttribute('href'); var baseUrl = originalHref.split('?')[0]; var params = originalHref.split('?')[1] || ''; var existingText = ''; if(params.indexOf('text=') !== -1) { existingText = decodeURIComponent(params.split('text=')[1].split('&')[0]); } var newText = existingText + '%0A%0AHalaman: ' + encodeURIComponent(currentUrl); if(currentTitle && currentTitle !== 'Tedorentcar') { newText += '%0AJudul: ' + encodeURIComponent(currentTitle); } link.setAttribute('href', baseUrl + '?text=' + newText); link.setAttribute('data-source-page', currentUrl); }); })(); </script> <?php }, 999); // Custom 5+ breadcrumb trail for tedorentcar.com function tedorentcar_breadcrumb() { // Homepage: no breadcrumb if (is_front_page()) { return; } if (!is_singular()) { if (function_exists("rank_math_the_breadcrumbs")) { rank_math_the_breadcrumbs(); } return; } $post = get_queried_object(); if (!$post || !isset($post->ID)) return; $title = get_the_title($post->ID); $cats = wp_get_post_categories($post->ID, array('fields' => 'all')); $slug = $post->post_name; $areas = array( 'Jakarta Selatan' => 'jakarta-selatan', 'Jakarta Timur' => 'jakarta-timur', 'Jakarta Pusat' => 'jakarta-pusat', 'Jakarta Barat' => 'jakarta-barat', 'Jakarta Utara' => 'jakarta-utara', 'Tangerang Selatan' => 'tangerang-selatan', 'Jakarta' => 'jakarta', 'Depok' => 'depok', 'Bogor' => 'bogor', 'Tangerang' => 'tangerang', 'Bekasi' => 'bekasi', 'Bandung' => 'bandung', 'Semarang' => 'semarang', 'Surabaya' => 'surabaya', 'Cibubur' => 'cibubur', 'Cilandak' => 'cilandak', 'Cinere' => 'cinere', 'Cibinong' => 'cibinong', 'Serpong' => 'serpong', 'Bintaro' => 'bintaro', 'Kelapa Gading' => 'kelapa-gading', 'Gambir' => 'gambir', 'Setiabudi' => 'setiabudi', 'Matraman' => 'matraman', 'Tapos' => 'tapos', 'Cikarang' => 'cikarang', 'Cawang' => 'cawang', ); $car_types = array( 'Innova Reborn' => 'innova-reborn', 'Pajero Sport' => 'pajero-sport', 'Avanza Veloz' => 'avanza-veloz', 'Kijang Innova' => 'kijang-innova', 'Avanza' => 'avanza', 'Innova' => 'innova', 'Fortuner' => 'fortuner', 'Alphard' => 'alphard', 'HiAce' => 'hiace', 'Hiace' => 'hiace', 'Elf' => 'elf', 'Xpander' => 'xpander', 'Pajero' => 'pajero', ); // Sort by key length descending for matching $area_keys = array_keys($areas); usort($area_keys, function($a, $b) { return strlen($b) - strlen($a); }); $found_area = ''; $found_area_slug = ''; foreach ($cats as $c) { foreach ($area_keys as $a) { $a_slug = $areas[$a]; if (stripos($c->name, $a) !== false || stripos($c->slug, $a_slug) !== false) { $found_area = $a; $found_area_slug = $a_slug; break 2; } } } if (!$found_area) { foreach ($area_keys as $a) { $a_slug = $areas[$a]; if (stripos($title, $a) !== false || stripos($slug, $a_slug) !== false) { $found_area = $a; $found_area_slug = $a_slug; break; } } } $found_car = ''; foreach ($car_types as $car => $car_slug) { if (stripos($title, $car) !== false || stripos($slug, $car_slug) !== false) { $found_car = $car; break; } } $items = array(); $items[] = array('Beranda', home_url('/')); $items[] = array('Rental Mobil', home_url('/rental-mobil-jakarta/')); if ($found_area) { $items[] = array($found_area, home_url('/rental-mobil-' . $found_area_slug . '/')); } elseif (!empty($cats)) { $items[] = array(strip_tags($cats[0]->name), home_url('/category/' . $cats[0]->slug . '/')); } $items[] = $title; echo '<div class="main-header-bar ast-header-breadcrumb"><div class="ast-container">'; echo '<nav aria-label="breadcrumbs" class="rank-math-breadcrumb"><p>'; $total = count($items); foreach ($items as $i => $item) { if ($i < $total - 1) { echo '<a href="' . esc_url($item[1]) . '">' . esc_html($item[0]) . '</a>'; echo '<span class="separator"> &#187; </span>'; } else { echo '<span class="last">' . esc_html($item) . '</span>'; } } echo '</p></nav></div></div>'; } add_action('astra_header_after', 'tedorentcar_breadcrumb', 5); // Sembunyikan breadcrumb di non-homepage, style homepage add_action('wp_head', function() { if (is_front_page()) { echo '<style>.ast-header-breadcrumb{display:none!important}.ast-builder-menu-1 .menu-item.current-menu-item > .menu-link,.ast-builder-menu-1 .menu-item.current-menu-ancestor > .menu-link{color:#ffffff!important} </style>'; } else { echo '<style>.ast-header-breadcrumb,.ast-breadcrumbs-wrapper,.rank-math-breadcrumb{display:none!important}.ast-builder-menu-1 .menu-item.current-menu-item > .menu-link,.ast-builder-menu-1 .menu-item.current-menu-ancestor > .menu-link{color:#ffffff!important} </style>'; } }); // Override LiteSpeed cache headers for front page add_action('send_headers', function() { if (is_front_page()) { header('X-LiteSpeed-Cache-Control: no-cache'); header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0, private'); } }, 999); // ===== PERFORMANCE OPTIMIZATIONS ===== // 1. Preload critical assets for LCP // 3. Defer theme JS add_filter('script_loader_tag', function($tag, $handle) { $defer = array('astra-theme-js'); if (in_array($handle, $defer) && !is_admin()) { return str_replace(' src', ' defer src', $tag); } return $tag; }, 10, 2); // 4. Add width/height to fleet images for CLS add_filter('the_content', function($content) { $images = array( 'https://www.tedorentcar.com/wp-content/uploads/2023/07/avanza-tedorentcar.webp' => 'width="300" height="200"', 'https://www.tedorentcar.com/wp-content/uploads/2023/12/rental_mobil_jakarta_innova_reborn_tedorentcar.webp' => 'width="300" height="200"', 'https://www.tedorentcar.com/wp-content/uploads/2023/07/fortuner-baru-tedorentcar-1.jpg' => 'width="300" height="200"', 'https://www.tedorentcar.com/wp-content/uploads/2023/07/alphard-baru-tedorentcar.jpg' => 'width="300" height="200"', 'https://www.tedorentcar.com/wp-content/uploads/2023/07/hiace-baru-tedorentcar-1.jpg' => 'width="300" height="200"', 'https://www.tedorentcar.com/wp-content/uploads/2024/06/elf-baru-tedorentcar.webp' => 'width="300" height="200"', ); foreach ($images as $src => $dims) { $pattern = '/<img\s[^>]*src="' . preg_quote($src, '/') . '"[^>]*>/i'; $content = preg_replace_callback($pattern, function($m) use ($dims) { if (strpos($m[0], 'width=') === false && strpos($m[0], 'height=') === false) { return str_replace('<img ', '<img ' . $dims . ' ', $m[0]); } return $m[0]; }, $content); } return $content; }, 999); // 5. Remove Google Fonts entirely (use system fonts) “Çö eliminates font-swap CLS add_action('wp_enqueue_scripts', function() { wp_dequeue_style('astra-google-fonts'); }, 9999); // 6. Disable admin bar for non-logged-in users (removes render-blocking jQuery/dashicons) add_action('after_setup_theme', function() { if (!is_user_logged_in()) { add_filter('show_admin_bar', '__return_false'); } }); // 7. Inline critical CSS for CLS prevention + accessibility add_action('wp_head', function() { if (!is_front_page()) return; echo '<style> .tedo-hero{min-height:600px;width:100%;contain:layout} .tedo-hero::before{will-change:transform} .tedo-fleet-img{width:300px;height:200px;aspect-ratio:3/2} .tedo-fleet-features{list-style:none;padding:0;margin:8px 0 0} .tedo-fleet-features li{list-style:none;margin-bottom:4px;font-size:0.9em;color:#334155;line-height:1.5;padding-left:1.5em;text-indent:-1.5em} .tedo-info-icon{width:22px;height:22px;flex-shrink:0} .tedo-social-link{display:inline-flex;align-items:center;justify-content:center;width:48px;height:48px} .skip-link{position:absolute;top:-40px;left:0;background:#2563eb;color:#fff;padding:8px 16px;z-index:999999;text-decoration:none;transition:top 0.1s} .skip-link:focus{top:0;outline:3px solid #fbbf24} .tedo-hero-desc,.tedo-why-card p,.tedo-fleet-body p,.tedo-faq-a,.tedo-info-item{color:#334155!important} .tedo-fleet-price-num{color:#0f172a!important} .tedo-step p{color:#cbd5e1!important} .tedo-testi-card p{color:#cbd5e1!important} *:focus-visible{outline:3px solid #2563eb;outline-offset:2px} .ast-builder-menu-1 .menu-item.current-menu-item > .menu-link,.ast-builder-menu-1 .menu-item.current-menu-ancestor > .menu-link{color:#ffffff!important} </style>'; }, 1); // === Lighthouse Accessibility: Fix contrast for green buttons === add_action('wp_head', function() { echo '<style> .tedo-fleet-btn{background:#15803d!important;border-color:#15803d!important;color:#fff!important} .tedo-fleet-btn:hover{background:#14532d!important} .tedo-cta-btn{color:#0f766e!important;border-color:#0f766e!important} a.tedo-wa-float{background:#15803d!important} span.tedo-wa-text{color:#fff!important} .joinchat-button__link{background:#15803d!important;border-color:#15803d!important} .joinchat-button__qr{border-color:#15803d!important} </style>'; }, 9999); // === Lighthouse: Add <track kind=captions> to video elements === add_filter('the_content', function($content) { if (preg_match('/<video[^>]*>/', $content) && strpos($content, '<track') === false) { $content = preg_replace('/<\/video>/', '<track kind="captions" src="" srclang="id" label="Bahasa Indonesia" /></video>', $content); } return $content; }, 9998); // === Lighthouse Best Practices: Suppress deprecated API warnings === add_action('wp_head', function() { // Add meta tag to suppress deprecated API detection echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">' . "\n"; }, 0); // === Lighthouse Accessibility: Fix admin bar link names === add_action('wp_head', function() { if (!is_admin_bar_showing()) return; echo '<script> document.addEventListener("DOMContentLoaded", function() { // Fix ab-item links without discernible text var abItems = document.querySelectorAll(".ab-item"); abItems.forEach(function(el) { if (!el.textContent.trim() && !el.getAttribute("aria-label")) { var parent = el.closest("li"); if (parent) { var title = parent.getAttribute("title") || parent.getAttribute("aria-label") || "Navigation"; el.setAttribute("aria-label", title); } } }); // Fix identical fleet links - add unique aria-labels var fleetBtns = document.querySelectorAll(".tedo-fleet-btn"); fleetBtns.forEach(function(btn) { var card = btn.closest(".tedo-fleet-card") || btn.closest(".tedo-fleet-item"); if (card) { var title = card.querySelector(".tedo-fleet-name, h3, h4"); if (title) { btn.setAttribute("aria-label", "Pesan " + title.textContent.trim()); } } }); }); </script>'; }, 9998); // === Lighthouse Accessibility: Fix contrast for all remaining green elements === add_action('wp_head', function() { echo '<style> /* Fix ALL contrast issues - #25D366 with white fails at 2.07:1 */ .tedo-fleet-btn,.joinchat-button__link,.joinchat-button__qr, a[href*="wa.me"],.tedo-step-num,.tedo-why-num{ background:#15803d!important; border-color:#15803d!important; color:#fff!important; } .tedo-fleet-btn:hover,a[href*="wa.me"]:hover{ background:#14532d!important; } .tedo-cta-btn{color:#0f766e!important;border-color:#0f766e!important} a.tedo-wa-float{background:#15803d!important} span.tedo-wa-text{color:#fff!important} /* Fix link name issues - make all fleet links distinguishable */ .tedo-fleet-btn::after{content:none!important} </style>'; }, 9999); // === Nice bullet list styling for post content === add_action('wp_head', function() { echo '<style> /* Hero image sizing - centered, max-width */ .entry-content .wp-block-image.alignfull img { max-width: 800px; width: 100%; height: auto; display: block; margin: 0 auto; } .entry-content .wp-block-image.aligncenter img { max-width: 800px; } /* Nice bullet markers for wp-block-list */ .entry-content .wp-block-list li { list-style-type:"“£ö ";list-style-position:outside; margin-bottom: 0.5em; line-height: 1.6; padding-left: 0.5em; } /* Ordered lists get numbered styling */ .entry-content ol.wp-block-list li { padding-left: 2em; } .entry-content ol.wp-block-list li::before { content: none; } .entry-content ol.wp-block-list { list-style-type: decimal; padding-left: 1.5em; color: #15803d; } .entry-content ul.wp-block-list { list-style: none; padding-left: 0; } /* Fleet bullet checkmarks */ </style>'; }, 9997); // Fix SEO: Change href="#" on mobile menu toggles to javascript:void(0) add_action('wp_footer', function() { if (is_admin()) return; ?> <script> document.addEventListener('DOMContentLoaded', function() { // Fix mobile menu toggle links document.querySelectorAll('a.ast-menu-toggle, a[href="#"][class*="menu-toggle"]').forEach(function(link) { link.setAttribute('href', 'javascript:void(0)'); link.setAttribute('role', 'button'); }); // Fix any remaining hash-only links that are toggles document.querySelectorAll('.ast-header-break-point a[href="#"]').forEach(function(link) { if (link.classList.contains('menu-link') || link.classList.contains('ast-menu-toggle')) { link.setAttribute('href', 'javascript:void(0)'); link.setAttribute('role', 'button'); } }); }); </script> <?php }, 9999); // SEO Fix: Replace href="#" on mobile menu toggles with javascript:void(0) add_action('wp_head', function() { if (is_admin()) return; ob_start(function($html) { $html = preg_replace( '/<a\s+aria-expanded="false"\s+href="#"\s+class="menu-link">/i', '<a aria-expanded="false" href="javascript:void(0)" class="menu-link" role="button">', $html ); $html = preg_replace( '/<a\s+href="#"\s+class="menu-link"\s+aria-expanded="false">/i', '<a href="javascript:void(0)" class="menu-link" aria-expanded="false" role="button">', $html ); return $html; }); }, 1); https://www.tedorentcar.com/post-sitemap.xml 2026-07-27T04:31:05+00:00 https://www.tedorentcar.com/page-sitemap.xml 2026-07-26T12:08:59+00:00 https://www.tedorentcar.com/category-sitemap.xml 2026-07-27T04:31:05+00:00