{"slug":"schema-injection-wordpress","title":"WordPress Schema Injection","tags":["schema","json-ld","local-seo","rank-math","structured-data"],"agent_summary":"WordPress schema markup: Rank Math Local SEO configuration, custom JSON-LD injection via wp_head for LocalBusiness and Service schemas, FAQ schema function, and validation via Google Rich Results Test.","trigger_phrases":["wordpress schema","json-ld wordpress","schema injection wordpress","local business schema wordpress","rank math schema","structured data wordpress","faq schema wordpress","service schema"],"runnable":true,"markdown":"\nSchema markup tells search engines what a page is. Rank Math handles standard schema; complex local business and service pages need custom JSON-LD injection.\n\n## Rank Math Schema Setup\n\n1. Rank Math > Titles & Meta > Local SEO — enter business name, address, phone, hours, coordinates\n2. Rank Math > Schema > Templates — assign schemas to post types\n3. Schema types to configure per page type:\n   - Home/About: Organization + LocalBusiness\n   - Service pages: Service\n   - Blog posts: Article\n   - FAQ sections: FAQPage\n   - Reviews: Review\n\n## NAP Consistency Rule\n\nNAP (Name, Address, Phone) in Rank Math **must exactly match GMB**:\n- Same business name — no abbreviations\n- Same address format (St vs Street)\n- Same phone format (include area code)\n- Same hours to the minute\n\n## Custom JSON-LD — LocalBusiness (functions.php)\n\n```php\nadd_action('wp_head', 'inject_local_business_schema');\n\nfunction inject_local_business_schema() {\n    if (!is_front_page() && !is_page('about')) return;\n\n    $schema = [\n        '@context'  => 'https://schema.org',\n        '@type'     => 'LocalBusiness',\n        'name'      => 'ACME Roofing',\n        'image'     => 'https://example.com/logo.png',\n        'telephone' => '+1-555-123-4567',\n        'address'   => [\n            '@type'           => 'PostalAddress',\n            'streetAddress'   => '123 Main St',\n            'addressLocality' => 'Miami',\n            'addressRegion'   => 'FL',\n            'postalCode'      => '33101',\n            'addressCountry'  => 'US',\n        ],\n        'geo' => [\n            '@type'     => 'GeoCoordinates',\n            'latitude'  => 25.7617,\n            'longitude' => -80.1918,\n        ],\n        'openingHoursSpecification' => [[\n            '@type'     => 'OpeningHoursSpecification',\n            'dayOfWeek' => ['Monday','Tuesday','Wednesday','Thursday','Friday'],\n            'opens'     => '08:00',\n            'closes'    => '18:00',\n        ]],\n        'url'        => home_url('/'),\n        'priceRange' => '$$',\n    ];\n\n    echo '<script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '</script>';\n}\n```\n\n## Service Schema (Service Post Type)\n\n```php\nadd_action('wp_head', function() {\n    if (!is_singular('service')) return;\n\n    $schema = [\n        '@context'    => 'https://schema.org',\n        '@type'       => 'Service',\n        'name'        => get_the_title(),\n        'description' => get_the_excerpt(),\n        'provider'    => [\n            '@type' => 'LocalBusiness',\n            'name'  => get_bloginfo('name'),\n        ],\n        'areaServed' => [\n            '@type' => 'City',\n            'name'  => 'Miami',\n        ],\n    ];\n\n    echo '<script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '</script>';\n});\n```\n\n## FAQ Schema\n\n```php\nfunction inject_faq_schema(array $faqs): void {\n    $items = array_map(function($faq) {\n        return [\n            '@type'          => 'Question',\n            'name'           => $faq['question'],\n            'acceptedAnswer' => ['@type' => 'Answer', 'text' => $faq['answer']],\n        ];\n    }, $faqs);\n\n    $schema = ['@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => $items];\n    echo '<script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '</script>';\n}\n```\n\n## Validation\n\n- Test at: https://search.google.com/test/rich-results\n- Validate JSON-LD syntax at: https://jsonld.com/json-ld-validator/\n- Check for errors in Google Search Console > Enhancements\n","html":"<p>Schema markup tells search engines what a page is. Rank Math handles standard schema; complex local business and service pages need custom JSON-LD injection.</p>\n<h2>Rank Math Schema Setup</h2>\n<ol>\n<li>Rank Math > Titles &#x26; Meta > Local SEO — enter business name, address, phone, hours, coordinates</li>\n<li>Rank Math > Schema > Templates — assign schemas to post types</li>\n<li>Schema types to configure per page type:\n<ul>\n<li>Home/About: Organization + LocalBusiness</li>\n<li>Service pages: Service</li>\n<li>Blog posts: Article</li>\n<li>FAQ sections: FAQPage</li>\n<li>Reviews: Review</li>\n</ul>\n</li>\n</ol>\n<h2>NAP Consistency Rule</h2>\n<p>NAP (Name, Address, Phone) in Rank Math <strong>must exactly match GMB</strong>:</p>\n<ul>\n<li>Same business name — no abbreviations</li>\n<li>Same address format (St vs Street)</li>\n<li>Same phone format (include area code)</li>\n<li>Same hours to the minute</li>\n</ul>\n<h2>Custom JSON-LD — LocalBusiness (functions.php)</h2>\n<pre><code class=\"language-php\">add_action('wp_head', 'inject_local_business_schema');\n\nfunction inject_local_business_schema() {\n    if (!is_front_page() &#x26;&#x26; !is_page('about')) return;\n\n    $schema = [\n        '@context'  => 'https://schema.org',\n        '@type'     => 'LocalBusiness',\n        'name'      => 'ACME Roofing',\n        'image'     => 'https://example.com/logo.png',\n        'telephone' => '+1-555-123-4567',\n        'address'   => [\n            '@type'           => 'PostalAddress',\n            'streetAddress'   => '123 Main St',\n            'addressLocality' => 'Miami',\n            'addressRegion'   => 'FL',\n            'postalCode'      => '33101',\n            'addressCountry'  => 'US',\n        ],\n        'geo' => [\n            '@type'     => 'GeoCoordinates',\n            'latitude'  => 25.7617,\n            'longitude' => -80.1918,\n        ],\n        'openingHoursSpecification' => [[\n            '@type'     => 'OpeningHoursSpecification',\n            'dayOfWeek' => ['Monday','Tuesday','Wednesday','Thursday','Friday'],\n            'opens'     => '08:00',\n            'closes'    => '18:00',\n        ]],\n        'url'        => home_url('/'),\n        'priceRange' => '$$',\n    ];\n\n    echo '&#x3C;script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '&#x3C;/script>';\n}\n</code></pre>\n<h2>Service Schema (Service Post Type)</h2>\n<pre><code class=\"language-php\">add_action('wp_head', function() {\n    if (!is_singular('service')) return;\n\n    $schema = [\n        '@context'    => 'https://schema.org',\n        '@type'       => 'Service',\n        'name'        => get_the_title(),\n        'description' => get_the_excerpt(),\n        'provider'    => [\n            '@type' => 'LocalBusiness',\n            'name'  => get_bloginfo('name'),\n        ],\n        'areaServed' => [\n            '@type' => 'City',\n            'name'  => 'Miami',\n        ],\n    ];\n\n    echo '&#x3C;script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '&#x3C;/script>';\n});\n</code></pre>\n<h2>FAQ Schema</h2>\n<pre><code class=\"language-php\">function inject_faq_schema(array $faqs): void {\n    $items = array_map(function($faq) {\n        return [\n            '@type'          => 'Question',\n            'name'           => $faq['question'],\n            'acceptedAnswer' => ['@type' => 'Answer', 'text' => $faq['answer']],\n        ];\n    }, $faqs);\n\n    $schema = ['@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => $items];\n    echo '&#x3C;script type=\"application/ld+json\">'\n       . wp_json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)\n       . '&#x3C;/script>';\n}\n</code></pre>\n<h2>Validation</h2>\n<ul>\n<li>Test at: https://search.google.com/test/rich-results</li>\n<li>Validate JSON-LD syntax at: https://jsonld.com/json-ld-validator/</li>\n<li>Check for errors in Google Search Console > Enhancements</li>\n</ul>\n"}