# Service Structured Data for a Services Post Type

> Adds Service JSON-LD (name, description, provider and area served) to single service pages, describing what your business offers.

- Type: PHP
- Runs: Frontend only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: schema, services, local-seo
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/seo-service-schema/

## Code

```php
// Post type and the areas you serve.
$wpide_service_type  = 'service';
$wpide_service_areas = array( 'Springfield', 'Shelbyville' );

add_action( 'wp_head', function () use ( $wpide_service_type, $wpide_service_areas ) {
    if ( ! is_singular( $wpide_service_type ) ) {
        return;
    }

    $post = get_queried_object();
    $data = array(
        '@context'    => 'https://schema.org',
        '@type'       => 'Service',
        'name'        => wp_strip_all_tags( get_the_title( $post ) ),
        'serviceType' => wp_strip_all_tags( get_the_title( $post ) ),
        'description' => wp_strip_all_tags( get_the_excerpt( $post ) ),
        'url'         => get_permalink( $post ),
        'image'       => get_the_post_thumbnail_url( $post, 'full' ),
        'provider'    => array( '@type' => 'Organization', 'name' => get_bloginfo( 'name' ), 'url' => home_url( '/' ) ),
        'areaServed'  => array_map( function ( $area ) {
            return array( '@type' => 'Place', 'name' => $area );
        }, $wpide_service_areas ),
    );

    echo '<script type="application/ld+json">' . wp_json_encode( array_filter( $data ), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG ) . "</script>\n";
} );
```

## Notes

Made for the Services post type snippet. Set the areas you serve.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Service Structured Data for a Services Post Type" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
