// FAQPage Schema Generator for Children's ABA Location Pages (function() { 'use strict'; // Only run on location pages if (!window.location.pathname.includes('/locations/')) { return; } // Function to extract FAQ data from the page function extractFAQData() { const faqs = []; // Try to find Elementor accordion widgets (nested-accordion) const accordions = document.querySelectorAll('.elementor-widget-nested-accordion, .e-n-accordion, [data-widget_type="nested-accordion.default"]'); if (accordions.length > 0) { accordions.forEach(accordion => { const items = accordion.querySelectorAll('.elementor-accordion-item, .e-n-accordion-item'); items.forEach(item => { const titleEl = item.querySelector('.elementor-accordion-title, .e-n-accordion-item-title'); const contentEl = item.querySelector('.elementor-accordion-body, .e-n-accordion-item-body'); if (titleEl && contentEl) { const question = titleEl.textContent.trim(); const answer = contentEl.textContent.trim(); if (question && answer) { faqs.push({ question, answer }); } } }); }); } // Fallback: Try to find h3 + p patterns that might be FAQs if (faqs.length === 0) { const mainContent = document.querySelector('.elementor, main, .entry-content, [role="main"]'); if (mainContent) { const headings = mainContent.querySelectorAll('h3, h4'); headings.forEach(heading => { // Look for paragraphs immediately following this heading let sibling = heading.nextElementSibling; let answerText = ''; // Collect text from following paragraphs until we hit another heading while (sibling && !sibling.matches('h2, h3, h4, h5, h6')) { if (sibling.matches('p')) { answerText += sibling.textContent.trim() + ' '; } sibling = sibling.nextElementSibling; } const question = heading.textContent.trim(); answerText = answerText.trim(); if (question && answerText && answerText.length > 10) { faqs.push({ question, answer: answerText }); } }); } } return faqs; } // Get page H1 function getPageH1() { const h1 = document.querySelector('h1, .page-title'); return h1 ? h1.textContent.trim() : document.title; } // Generate FAQPage schema function generateFAQPageSchema(pageTitle, faqs) { const faqItemArray = faqs.map(faq => ({ '@type': 'Question', 'name': faq.question, 'acceptedAnswer': { '@type': 'Answer', 'text': faq.answer } })); return { '@context': 'https://schema.org', '@type': 'FAQPage', 'mainEntity': faqItemArray, 'url': window.location.href, 'name': pageTitle }; } // Inject schema into head function injectSchema(schema) { const scriptTag = document.createElement('script'); scriptTag.type = 'application/ld+json'; scriptTag.textContent = JSON.stringify(schema); scriptTag.id = 'children-aba-faqpage-schema'; // For identification/removal // Check if schema already exists to avoid duplicates const existing = document.getElementById('children-aba-faqpage-schema'); if (existing) { existing.remove(); } document.head.appendChild(scriptTag); } // Main execution function init() { const faqs = extractFAQData(); // Only inject schema if we found FAQ content if (faqs.length > 0) { const pageTitle = getPageH1(); const schema = generateFAQPageSchema(pageTitle, faqs); injectSchema(schema); console.log('[Children\'s ABA] FAQPage schema injected with', faqs.length, 'FAQs'); } else { console.log('[Children\'s ABA] No FAQ content found on this page'); } } // Wait for DOM to be fully loaded if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { // DOM is already loaded setTimeout(init, 500); } })();
(function() { const locationMap = { "in-home-aba-therapy-raleigh-nc": ["Durham", "Chapel Hill", "Cary", "Wake Forest", "Morrisville"], "in-home-aba-therapy-durham-nc": ["Raleigh", "Chapel Hill", "Cary", "Morrisville", "Apex"], "in-home-aba-therapy-cary-nc": ["Raleigh", "Durham", "Apex", "Holly Springs", "Morrisville"], "in-home-aba-therapy-apex-nc": ["Cary", "Raleigh", "Holly Springs", "Fuquay-Varina", "Durham"], "in-home-aba-therapy-chapel-hill-nc": ["Raleigh", "Durham", "Pittsboro", "Sanford", "Cary"], "in-home-aba-therapy-morrisville-nc": ["Raleigh", "Durham", "Cary", "Wake Forest", "Apex"], "in-home-aba-therapy-holly-springs-nc": ["Apex", "Cary", "Fuquay-Varina", "Raleigh", "Wake Forest"], "in-home-aba-therapy-fuquay-varina-nc": ["Holly Springs", "Sanford", "Apex", "Cary", "Raleigh"], "in-home-aba-therapy-garner-nc": ["Raleigh", "Wake Forest", "Clayton", "Knightdale", "Morrisville"], "in-home-aba-therapy-wake-forest-nc": ["Raleigh", "Garner", "Knightdale", "Morrisville", "Clayton"], "in-home-aba-therapy-knightdale-nc": ["Raleigh", "Wake Forest", "Clayton", "Garner", "Durham"], "in-home-aba-therapy-clayton-nc": ["Raleigh", "Knightdale", "Smithfield", "Wake Forest", "Garner"], "in-home-aba-therapy-smithfield-nc": ["Clayton", "Raleigh", "Sanford", "Knightdale", "Garner"], "in-home-aba-therapy-sanford-nc": ["Fuquay-Varina", "Chapel Hill", "Pittsboro", "Smithfield", "Raleigh"], "in-home-aba-therapy-pittsboro-nc": ["Chapel Hill", "Sanford", "Raleigh", "Cary", "Durham"], "in-home-aba-therapy-greensboro-nc": ["High Point", "Winston-Salem", "Burlington", "Kernersville", "Summerfield"], "in-home-aba-therapy-high-point-nc": ["Greensboro", "Winston-Salem", "Kernersville", "Thomasville", "Jamestown"], "in-home-aba-therapy-winston-salem-nc": ["Greensboro", "High Point", "Kernersville", "Summerfield", "Jamestown"], "in-home-aba-therapy-burlington-nc": ["Greensboro", "Asheboro", "High Point", "Lexington", "Kernersville"], "in-home-aba-therapy-kernersville-nc": ["Greensboro", "High Point", "Winston-Salem", "Thomasville", "Summerfield"], "in-home-aba-therapy-thomasville-nc": ["High Point", "Kernersville", "Asheboro", "Lexington", "Greensboro"], "in-home-aba-therapy-asheboro-nc": ["Thomasville", "Greensboro", "Burlington", "Lexington", "High Point"], "in-home-aba-therapy-lexington-nc": ["Asheboro", "Thomasville", "Winston-Salem", "Greensboro", "Kernersville"], "in-home-aba-therapy-jamestown-nc": ["High Point", "Winston-Salem", "Greensboro", "Summerfield", "Kernersville"], "in-home-aba-therapy-summerfield-nc": ["Greensboro", "Winston-Salem", "Jamestown", "High Point", "Kernersville"], "in-home-aba-therapy-wilmington-nc": ["Leland", "Hampstead", "Jacksonville", "Carolina Beach", "Burgaw"], "in-home-aba-therapy-leland-nc": ["Wilmington", "Burgaw", "Hampstead", "Southport", "Jacksonville"], "in-home-aba-therapy-hampstead-nc": ["Wilmington", "Leland", "Jacksonville", "Sneads Ferry", "Carolina Beach"], "in-home-aba-therapy-jacksonville-nc": ["Wilmington", "Hampstead", "Sneads Ferry", "Surf City", "Leland"], "in-home-aba-therapy-sneads-ferry-nc": ["Jacksonville", "Surf City", "Hampstead", "Carolina Beach", "Wilmington"], "in-home-aba-therapy-surf-city-nc": ["Sneads Ferry", "Wrightsville Beach", "Carolina Beach", "Jacksonville", "Hampstead"], "in-home-aba-therapy-carolina-beach-nc": ["Wrightsville Beach", "Surf City", "Wilmington", "Sneads Ferry", "Leland"], "in-home-aba-therapy-wrightsville-beach-nc": ["Wilmington", "Carolina Beach", "Surf City", "Hampstead", "Leland"], "in-home-aba-therapy-burgaw-nc": ["Leland", "Wilmington", "Hampstead", "Southport", "Jacksonville"], "in-home-aba-therapy-southport-nc": ["Leland", "Burgaw", "Wilmington", "Carolina Beach", "Hampstead"] }; const slug = window.location.pathname.replace(/\/$/, '').split('/').pop(); const nearby = locationMap[slug]; if (!nearby) return; const links = nearby.map(city => { const slug = 'in-home-aba-therapy-' + city.toLowerCase().replace(/\s+/g, '-') + '-nc'; return '