< ? php function mytheme_child_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css'); } add_action('wp_enqueue_scripts', 'mytheme_child_enqueue_styles'); // Paksa WordPress baca page template di FSE theme add_filter('theme_page_templates', function ($templates, $theme, $post, $post_type) { return $templates; }, 10, 4); // Otomatis set template "HTML Murni" untuk setiap halaman yang dibuat/disimpan add_action('wp_insert_post', function ($post_id, $post, $update) { // Hanya untuk halaman (bukan post/custom post type lain) if ($post->post_type !== 'page') return; // Hanya kalau template belum di-set $current_template = get_post_meta($post_id, '_wp_page_template', true); if (empty($current_template) || $current_template === 'default') { update_post_meta($post_id, '_wp_page_template', 'template-html-murni.php'); } }, 10, 3); // Set default block untuk halaman baru menjadi Custom HTML add_filter('default_content', function ($content, $post) { if ($post->post_type === 'page' || $post->post_type === 'post') { $content = ' '; } return $content; }, 10, 2); // Auto fokus ke blok Custom HTML saat halaman baru dibuka (SKIP) // Judul halaman & slug langsung berubah otomatis add_action('admin_footer', function () { // Cek halaman edit post/page tanpa get_current_screen() global $pagenow; if ($pagenow !== 'post.php' && $pagenow !== 'post-new.php') return; ? > < script > (function () { console.log('[AutoMeta] Script loaded!'); function extractAndUpdate(html) { const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); const titleFromTag = doc.querySelector('title')?.innerText?.trim(); const titleFromOG = doc.querySelector('meta[property="og:title"]')?.getAttribute('content')?.trim(); const title = titleFromTag || titleFromOG || ''; const description = doc.querySelector('meta[name="description"]')?.getAttribute('content')?.trim() || ''; console.log('=== AutoMeta Result ==='); console.log('Title:', title || '(tidak ditemukan)'); console.log('Desc :', description || '(tidak ditemukan)'); console.log('======================='); if (title) { const selectors = [ '.editor-post-title__input', '[aria-label="Add title"]', 'textarea[aria-label="Add title"]', '.wp-block-post-title', '[data-title="Title"]', ]; let titleField = null; for (const sel of selectors) { titleField = document.querySelector(sel); if (titleField) { console.log('[AutoMeta] Title field ditemukan:', sel); break; } } if (titleField) { const currentTitle = (titleField.value || titleField.innerText || '').trim(); if (!currentTitle) { if (titleField.tagName === 'TEXTAREA' || titleField.tagName === 'INPUT') { const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value') || Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value'); setter.set.call(titleField, title); titleField.dispatchEvent(new Event('input', { bubbles: true })); } else { titleField.focus(); document.execCommand('selectAll', false, null); document.execCommand('insertText', false, title); } console.log('[AutoMeta] Judul diset:', title); } } else { console.log('[AutoMeta] Title field tidak ditemukan! Semua contenteditable:'); document.querySelectorAll('[contenteditable]').forEach((el, i) => { console.log('#' + i, el.tagName, '|', el.className, '|', el.getAttribute('aria-label')); }); } } if (description) { const excerptField = document.querySelector('.editor-post-excerpt textarea'); if (excerptField) { const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value'); setter.set.call(excerptField, description); excerptField.dispatchEvent(new Event('input', { bubbles: true })); console.log('[AutoMeta] Excerpt diset:', description); } } } // Tunggu textarea Custom HTML muncul let attempts = 0; const tryWatch = setInterval(function () { attempts++; // Coba CodeMirror (Gutenberg modern) const cmEl = document.querySelector('.block-editor-plain-text, .CodeMirror, [role="textbox"].block-editor-rich-text__editable'); // Cari semua div contenteditable yang bukan judul const allEditable = document.querySelectorAll('[contenteditable="true"]'); let htmlEditor = null; allEditable.forEach(el => { // Skip judul if (el.classList.contains('editor-post-title__input')) return; if (el.getAttribute('aria-label') === 'Add title') return; // Ambil yang pertama bukan judul if (!htmlEditor) htmlEditor = el; }); // Coba juga CodeMirror instance const cmInstance = document.querySelector('.CodeMirror'); if (cmInstance && cmInstance.CodeMirror && !cmInstance._autoMetaAttached) { cmInstance._autoMetaAttached = true; clearInterval(tryWatch); console.log('[AutoMeta] CodeMirror ditemukan setelah', attempts, 'percobaan'); cmInstance.CodeMirror.on('change', function (cm) { clearTimeout(window._metaTimeout); window._metaTimeout = setTimeout(function () { extractAndUpdate(cm.getValue()); }, 1000); }); } else if (htmlEditor && !htmlEditor._autoMetaAttached) { htmlEditor._autoMetaAttached = true; clearInterval(tryWatch); console.log('[AutoMeta] contenteditable editor ditemukan setelah', attempts, 'percobaan'); htmlEditor.addEventListener('input', function () { clearTimeout(window._metaTimeout); window._metaTimeout = setTimeout(function () { extractAndUpdate(htmlEditor.innerText || htmlEditor.value || ''); }, 1000); }); } if (attempts > 60) { clearInterval(tryWatch); console.log('[AutoMeta] Timeout - editor tidak ditemukan'); // Debug: tampilkan semua yang ada document.querySelectorAll('[contenteditable]').forEach((el, i) => { console.log('contenteditable #' + i, '|', el.className, '|', el.getAttribute('aria-label')); }); } }, 300); })(); < / script > < ? php }); https://aipreneurconsulting.com/post-sitemap.xml 2026-05-13T03:58:46+00:00 https://aipreneurconsulting.com/page-sitemap.xml 2026-05-13T08:42:58+00:00 https://aipreneurconsulting.com/category-sitemap.xml 2026-05-13T03:58:46+00:00 https://aipreneurconsulting.com/author-sitemap.xml 2026-05-13T05:32:09+00:00