Type something to search...
How to add schema markup to a WordPress website?

How to add schema markup to a WordPress website?

You can add schema markup to a WordPress website in three main ways: let an SEO plugin like Yoast SEO, Rank Math, or All in One SEO generate it automatically, use a dedicated schema plugin for more specialized types, or output your own JSON-LD code with a small function hooked into wp_head. For most sites, an SEO plugin covers the essentials, such as Organization, WebSite, Article, and Breadcrumb schema, and you only need custom code or extra plugins for specific cases like recipes, events, products, or local business details.

Schema markup helps search engines understand what your content is about, and it can make your pages eligible for rich results like star ratings, recipe cards, and event listings. This guide explains what schema is, which types matter for WordPress sites, how to add it with plugins or code, and how to test that it's working.

What Is Schema Markup?

Schema markup is structured data that describes your content in a standardized vocabulary defined by Schema.org, a project backed by major search engines. Instead of leaving Google to guess that a page is a recipe, an article, or a local business, schema spells it out in a machine-readable format.

For example, a human can tell that "4.8 stars from 120 reviews" is a rating, but schema tells search engines explicitly that the page contains an AggregateRating with a ratingValue of 4.8 and a reviewCount of 120.

Formats: JSON-LD, Microdata, and RDFa

Structured data can be written in three formats:

  • JSON-LD: A block of JavaScript Object Notation inside a <script type="application/ld+json"> tag. It's separate from your visible HTML, easy to maintain, and the format Google recommends.
  • Microdata: Attributes added directly to HTML elements, like itemprop="name".
  • RDFa: Similar to Microdata, using a different set of attributes.

This guide uses JSON-LD throughout, since it's the easiest to add and manage in WordPress.

Why Schema Markup Matters

Schema isn't a direct ranking factor, but it offers real benefits:

  • Rich results eligibility: Pages with valid schema can qualify for enhanced search listings, such as recipe images, review stars, product prices, event dates, and breadcrumbs.
  • Better understanding: Structured data helps search engines connect your content to entities like your organization, authors, and products.
  • Higher click-through rates: Rich results often stand out and can attract more clicks than plain blue links.
  • Knowledge panel support: Organization and Person schema can help search engines associate your site with your brand or name.
  • Clarity for other systems: Structured data is increasingly used by AI search features and other tools that summarize web content.

Keep in mind that Google decides whether to show rich results. Valid markup makes you eligible but doesn't guarantee display.

Common Schema Types for WordPress Sites

Different sites need different types. Here are the ones most WordPress sites use:

  • Organization or Person: Describes who runs the site, including name, logo, and social profiles.
  • WebSite: Describes the site itself, including its name.
  • Article, BlogPosting, or NewsArticle: For posts, including headline, author, dates, and image.
  • BreadcrumbList: Shows the page's position in your site hierarchy.
  • Product and Offer: For e-commerce pages, including price, availability, and reviews. WooCommerce outputs basic product schema automatically.
  • LocalBusiness: For businesses with physical locations, including address, opening hours, and phone number.
  • Recipe: For cooking sites, including ingredients, cook time, and nutrition.
  • Event: For concerts, webinars, classes, and other events.
  • Review and AggregateRating: For reviews of products, books, software, and more.
  • VideoObject: For pages built around a video.
  • FAQPage: For pages with a list of questions and answers.

A note on FAQ and HowTo markup: Google significantly reduced FAQ rich results in 2023, limiting them mainly to well-known government and health sites, and it has since stopped showing HowTo rich results. You can still use this markup to describe your content, but don't expect it to change your search appearance.

Method 1: Use an SEO Plugin

If you already use a major SEO plugin, you likely have solid baseline schema without doing anything.

Yoast SEO

Yoast outputs a connected schema graph on every page, including WebSite, WebPage, Organization or Person, Article for posts, and BreadcrumbList.

  1. Set up your site representation: Go to Yoast SEO > Settings > Site representation and choose whether your site represents an organization or a person. Add the name, logo, and social profiles.
  2. Set default content types: Under Yoast SEO > Settings > Content types, choose the default schema page and article types for each post type.
  3. Override per post: In the Yoast panel for a post, open the Schema tab to change the page or article type for that specific post.
  4. Use schema blocks: Yoast includes FAQ and How-to blocks that output matching structured data.

Rank Math

Rank Math includes a schema generator with many types built in.

  1. Set global defaults: Go to Rank Math > Titles & Meta > Local SEO (or the Knowledge Graph settings) to define your organization or person details.
  2. Choose default schema per post type: Under Rank Math > Titles & Meta > Posts, pick a default schema type, such as Article.
  3. Add schema to a post: In the editor, open the Rank Math sidebar, go to the Schema tab, and click "Schema Generator" to choose types like Recipe, Event, Product, or Course and fill in the fields.
  4. Advanced features: Some features, such as custom schema builders and importing schema from other pages, require Rank Math Pro.

All in One SEO

  1. Configure your site: Go to All in One SEO > Search Appearance > Global Settings and set up your Knowledge Graph details.
  2. Choose defaults per content type: Under Content Types, select a default schema type.
  3. Add schema per post: In the AIOSEO settings panel for a post, open the Schema tab to add or edit schema types using the schema generator.

Method 2: Use a Dedicated Schema Plugin

If your SEO plugin doesn't cover a type you need, or you want more fine-grained control, a dedicated schema plugin can help:

  • Schema & Structured Data for WP & AMP: A free plugin supporting a long list of schema types, with conditional rules for where each type appears.
  • Schema Pro: A premium plugin that lets you map schema fields to existing post data and custom fields, so markup is created automatically across many posts.
  • WP Recipe Maker: For recipe sites, it outputs detailed Recipe schema from its recipe cards.
  • The Events Calendar: Adds Event schema to event listings.

Before adding one, check what your SEO plugin already outputs. Two plugins generating overlapping schema for the same page can create conflicting or duplicate data. Most dedicated schema plugins let you disable specific types to avoid overlap.

Method 3: Add Custom JSON-LD With Code

Custom code is useful when you need a schema type your plugins don't handle, or when you want lightweight markup without an SEO plugin. The safest approach is to generate JSON-LD in PHP from real post data and print it in the page's <head> using the wp_head hook.

Add the following snippets to a custom plugin or your child theme's functions.php. Always back up your site before editing theme files.

Article Schema for Blog Posts

Only use this if your SEO plugin isn't already outputting Article schema, or you'll end up with duplicates.

function sajjad_article_schema() {
    if ( ! is_singular( 'post' ) ) {
        return;
    }

    $post_id = get_queried_object_id();
    $author  = get_userdata( get_post_field( 'post_author', $post_id ) );

    $schema = array(
        '@context'         => 'https://schema.org',
        '@type'            => 'BlogPosting',
        'headline'         => wp_strip_all_tags( get_the_title( $post_id ) ),
        'description'      => wp_strip_all_tags( get_the_excerpt( $post_id ) ),
        'datePublished'    => get_the_date( 'c', $post_id ),
        'dateModified'     => get_the_modified_date( 'c', $post_id ),
        'mainEntityOfPage' => array(
            '@type' => 'WebPage',
            '@id'   => get_permalink( $post_id ),
        ),
        'author'           => array(
            '@type' => 'Person',
            'name'  => $author ? $author->display_name : '',
            'url'   => $author ? get_author_posts_url( $author->ID ) : '',
        ),
        'publisher'        => array(
            '@type' => 'Organization',
            'name'  => get_bloginfo( 'name' ),
            'url'   => home_url( '/' ),
        ),
    );

    if ( has_post_thumbnail( $post_id ) ) {
        $schema['image'] = get_the_post_thumbnail_url( $post_id, 'full' );
    }

    $logo_id = get_theme_mod( 'custom_logo' );
    if ( $logo_id ) {
        $schema['publisher']['logo'] = array(
            '@type' => 'ImageObject',
            'url'   => wp_get_attachment_image_url( $logo_id, 'full' ),
        );
    }

    printf(
        '<script type="application/ld+json">%s</script>' . "\n",
        wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG )
    );
}
add_action( 'wp_head', 'sajjad_article_schema' );

Using wp_json_encode() with the JSON_HEX_TAG flag ensures special characters are escaped correctly, so a quote or angle bracket in a post title can't break the JSON or close the script tag early.

Organization Schema on the Homepage

function sajjad_organization_schema() {
    if ( ! is_front_page() ) {
        return;
    }

    $schema = array(
        '@context' => 'https://schema.org',
        '@type'    => 'Organization',
        'name'     => get_bloginfo( 'name' ),
        'url'      => home_url( '/' ),
        'sameAs'   => array(
            'https://www.linkedin.com/company/your-company',
            'https://www.youtube.com/@yourchannel',
        ),
    );

    $logo_id = get_theme_mod( 'custom_logo' );
    if ( $logo_id ) {
        $schema['logo'] = wp_get_attachment_image_url( $logo_id, 'full' );
    }

    printf(
        '<script type="application/ld+json">%s</script>' . "\n",
        wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG )
    );
}
add_action( 'wp_head', 'sajjad_organization_schema' );

Replace the sameAs URLs with your real profiles.

LocalBusiness Schema

For a business with a physical location, here's an example of what the finished JSON-LD might look like. You can output it on your contact or homepage using the same wp_head pattern, building the array in PHP:

{
  "@context": "https://schema.org",
  "@type": "LocalBusiness",
  "name": "Example Bakery",
  "url": "https://example.com/",
  "telephone": "+1-555-0100",
  "image": "https://example.com/wp-content/uploads/storefront.jpg",
  "address": {
    "@type": "PostalAddress",
    "streetAddress": "123 Main Street",
    "addressLocality": "Springfield",
    "addressRegion": "IL",
    "postalCode": "62701",
    "addressCountry": "US"
  },
  "openingHoursSpecification": [
    {
      "@type": "OpeningHoursSpecification",
      "dayOfWeek": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
      "opens": "08:00",
      "closes": "18:00"
    }
  ]
}

Use a more specific type if one fits, such as Bakery, Dentist, or Restaurant, since these are all subtypes of LocalBusiness.

Page-Specific Schema With Custom Fields

For schema that varies by page, such as an event date or a product's price, store the values in custom fields and read them in your function. Here's a simple example for Event schema using post meta:

function sajjad_event_schema() {
    if ( ! is_singular( 'event' ) ) {
        return;
    }

    $post_id    = get_queried_object_id();
    $start_date = get_post_meta( $post_id, 'event_start', true ); // e.g. 2026-11-05T19:00:00+00:00
    $venue      = get_post_meta( $post_id, 'event_venue', true );
    $city       = get_post_meta( $post_id, 'event_city', true );

    if ( ! $start_date || ! $venue ) {
        return;
    }

    $schema = array(
        '@context'            => 'https://schema.org',
        '@type'               => 'Event',
        'name'                => wp_strip_all_tags( get_the_title( $post_id ) ),
        'startDate'           => sanitize_text_field( $start_date ),
        'eventStatus'         => 'https://schema.org/EventScheduled',
        'eventAttendanceMode' => 'https://schema.org/OfflineEventAttendanceMode',
        'location'            => array(
            '@type'   => 'Place',
            'name'    => sanitize_text_field( $venue ),
            'address' => sanitize_text_field( $city ),
        ),
        'url'                 => get_permalink( $post_id ),
    );

    printf(
        '<script type="application/ld+json">%s</script>' . "\n",
        wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG )
    );
}
add_action( 'wp_head', 'sajjad_event_schema' );

This assumes an event custom post type. Adjust the post type and meta keys to match your setup.

Extending Your SEO Plugin Instead

If you use Yoast SEO or Rank Math, both provide filters for modifying their schema output, such as wpseo_schema_graph in Yoast and rank_math/json_ld in Rank Math. Extending the plugin's graph keeps everything connected in a single structured data block, which is cleaner than printing separate scripts. Check each plugin's developer documentation for the exact structure before using these filters.

Step 4: Test Your Schema Markup

Always test after adding or changing schema.

  1. Google Rich Results Test: Visit Google's Rich Results Test and enter your page URL. It shows which rich result types the page is eligible for and flags errors or warnings.
  2. Schema Markup Validator: The validator at validator.schema.org checks all Schema.org markup, including types Google doesn't use for rich results.
  3. Google Search Console: Under the Enhancements section (and related rich result reports), Search Console lists valid items and errors across your whole site after Google crawls it.
  4. View source: In your browser, view the page source and search for application/ld+json to see exactly what's being output and spot duplicates.

Fix errors first, since they can prevent rich results entirely. Warnings are usually about optional properties, and adding them can improve your eligibility.

Schema Markup Best Practices

  • Mark up what's visible: Schema must describe content that users can actually see on the page. Adding fake reviews or hidden content violates Google's guidelines and can lead to a manual action.
  • Be accurate: Prices, dates, and availability in schema should match the page exactly.
  • Avoid duplicates: Don't let multiple plugins and custom code output the same type for the same page.
  • Use the most specific type: Recipe is better than Article for a recipe, and Dentist is better than LocalBusiness for a dental practice.
  • Don't mark up self-serving reviews: Google doesn't show review stars for reviews a business publishes about itself on its own LocalBusiness or Organization pages.
  • Keep it updated: If you change your logo, address, or opening hours, update your schema too.
  • Re-test after updates: Plugin updates and theme changes can alter schema output.

FAQ: Schema Markup in WordPress

WordPress core adds very little structured data on its own. Most schema comes from your theme, an SEO plugin, or plugins like WooCommerce, which outputs product markup.

Not directly. Schema helps search engines understand your content and can make pages eligible for rich results, which may improve click-through rates, but it doesn't boost rankings by itself.

JSON-LD is recommended by Google and is the easiest to add and maintain in WordPress, because it sits in its own script tag rather than being mixed into your HTML.

Valid markup only makes a page eligible. Google decides whether to show rich results based on quality, relevance, and the search query. Check the Rich Results Test for errors first.

You can, but it often leads to duplicate or conflicting markup. If you add a dedicated schema plugin alongside your SEO plugin, disable overlapping types in one of them.

Google now shows FAQ rich results mainly for well-known government and health sites, so most sites won't see a visual change. The markup is harmless and still describes your content, but it shouldn't be a priority.

Baseline schema like Organization, WebSite, and BreadcrumbList is useful site-wide. Specific types like Recipe, Product, or Event only belong on pages that actually contain that content.


Conclusion

Adding schema markup to a WordPress website is easier than it sounds. An SEO plugin like Yoast SEO, Rank Math, or All in One SEO handles the essentials automatically, dedicated plugins cover specialized types like recipes and events, and a few lines of PHP let you output custom JSON-LD for anything else.

Whichever method you use, keep your markup accurate, match it to what's visible on the page, avoid duplicate output, and test it with Google's Rich Results Test and the Schema Markup Validator. Done well, structured data gives search engines a clear picture of your content and gives your pages the best chance at standing out in search results.

Tags :
Share :

Related Posts

What are the best WordPress security plugins?

What are the best WordPress security plugins?

The best WordPress security plugins for most sites are Wordfence, Sucuri Security, Solid Security, MalCare, All-In-One Security (AIOS), Patchstack, a

Dive Deeper
What is the difference between posts and pages in WordPress?

What is the difference between posts and pages in WordPress?

The main difference between posts and pages in WordPress is that posts are timely, dated entries that appear in your blog feed, archives, and RSS fee

Dive Deeper
How much does it cost to build a WordPress website?

How much does it cost to build a WordPress website?

Building a WordPress website can cost anywhere from roughly the price of a domain and a year of budget hosting, if you do it yourself with free tools

Dive Deeper