Why Add Schema Without a Plugin?
WordPress plugins for schema markup like Rank Math and Yoast are excellent tools, but they're not always the right choice. Here's when going plugin-free makes sense:
- You want full control over exactly what schema is added and where
- Your site is performance-focused and every plugin adds overhead
- You only need schema on specific pages, not sitewide
- You're using a headless or custom WordPress setup where plugins may interfere
- You already have a lean plugin stack and want to keep it that way
Generate your schema first
15+ free JSON-LD generators, no signup required
3 Methods: Which Should You Use?
There are three main ways to add schema markup to WordPress without a plugin. Each suits a different situation:
| Method | Best For | Survives Updates | Difficulty |
|---|---|---|---|
| Method 1: functions.php | Sitewide schema (all pages) | â Yes (child theme) | Intermediate |
| Method 2: header.php | Sitewide schema (all pages) | â No (theme updates) | Beginner |
| Method 3: Block Editor | Per-page / per-post schema | â Yes | Beginner |
Method 1: Using functions.php (Recommended)
This is the most robust method for adding schema sitewide. It uses WordPress's wp_head action hook to inject your schema into every page's head tag automatically.
- Log in to your WordPress Admin
- Go to Appearance â Theme File Editor
- In the right panel, select your child theme
- Click on functions.php
Scroll to the bottom of functions.php and paste this code. Replace the schema inside the heredoc with your own generated JSON-LD:
add_action( 'wp_head', 'schemify_add_schema_markup' ); function schemify_add_schema_markup() { echo '<script type="application/ld+json">'; echo '{ "@context": "https://schema.org", "@type": "WebSite", "name": "Your Site Name", "url": "https://yoursite.com" }'; echo '</script>'; }
Click Update File to save. Your schema is now added to every page on your site.
You can add different schema to different pages using WordPress conditional tags like is_single(), is_page(), and is_home():
add_action( 'wp_head', 'schemify_conditional_schema' ); function schemify_conditional_schema() { // Add LocalBusiness schema on homepage only if ( is_front_page() ) { echo '<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "LocalBusiness", "name": "Your Business", "url": "https://yoursite.com" } </script>'; } // Add Article schema on single blog posts if ( is_single() ) { $title = get_the_title(); $date = get_the_date( 'Y-m-d' ); $url = get_permalink(); echo "<script type='application/ld+json'> { \"@context\": \"https://schema.org\", \"@type\": \"BlogPosting\", \"headline\": \"{$title}\", \"datePublished\": \"{$date}\", \"url\": \"{$url}\", \"author\": {\"@type\": \"Organization\", \"name\": \"Schemify\"} } </script>"; } }
Method 2: Editing header.php
This is the simplest method: you paste your schema directly into your theme's header template file. The downside is that it gets overwritten when your theme updates, so always use a child theme.
- Go to Appearance â Theme File Editor
- Select your child theme from the dropdown
- Click header.php in the right sidebar
- If header.php doesn't exist in your child theme, create it by copying from the parent theme
Find the closing </head> tag in header.php and paste your JSON-LD immediately before it:
<!-- Other head tags above --> <!-- Paste your schema here --> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "WebSite", "name": "Your Site Name", "url": "https://yoursite.com" } </script> <?php wp_head(); ?> </head>
Click Update File to save.
Method 3: Block Editor (Per-Page Schema)
This is the easiest method for adding schema to individual posts or pages without touching any theme files. It uses the Custom HTML block in WordPress's block editor (Gutenberg).
- Go to Posts or Pages in WordPress admin
- Click Edit on the post or page you want to add schema to
- The block editor will open
- Click the + Add Block button
- Search for "Custom HTML"
- Click to add the Custom HTML block
- Place it anywhere on the page; the schema is invisible to visitors
Paste your complete JSON-LD schema, including the script tags, directly into the Custom HTML block:
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [ { "@type": "Question", "name": "Your question here?", "acceptedAnswer": { "@type": "Answer", "text": "Your answer here." } } ] } </script>
Click Update or Publish to save. Your schema is now live on that specific page only.
Step 4: Validate Your Schema
After adding your schema to WordPress, always validate it before considering the job done. Use both tools:
Go to the Schemify Schema Validator, paste your JSON-LD code, and click Validate. The tool checks your JSON syntax, identifies your schema type, and highlights any missing required fields all instantly without needing a live URL.
Once your page is live, go to Google's Rich Results Test and paste your page URL. Google will confirm whether your schema is valid and whether it qualifies for rich results. Any errors shown here need to be fixed before Google will display rich results for your page.
In Google Search Console, go to the Enhancements section in the left sidebar. Here you'll see reports for each rich result type detected on your site, including any errors, warnings, or valid items. This is your ongoing monitoring dashboard for schema performance.
Common Mistakes to Avoid
- Editing the parent theme directly: Always use a child theme. Parent theme edits are lost on every theme update.
- Forgetting to escape quotes in PHP: When using the echo method in functions.php, use single quotes for the outer string and escape any double quotes inside the JSON with backslash:
\" - Adding schema in the body instead of the head: JSON-LD should go in the
<head>tag. The custom HTML block method is an exception. Google can read JSON-LD from the body too, but head placement is best practice. - Not validating after adding: A small PHP syntax error can break your entire site. Always validate in a staging environment first if possible.
- Using the same schema on every page: Don't add FAQPage schema sitewide; only add it to pages that actually have FAQ content. Mismatched schema is a Google policy violation.