'BlogPosting', 'page' => 'WebPage', ); $schema_type = isset( $type_map[ $post->post_type ] ) ? $type_map[ $post->post_type ] : 'Article'; /** * Schema.org type for the post (overridable for custom post types). * * @param string $schema_type Type. * @param WP_Post $post Post. */ $schema_type = (string) apply_filters( 'adg_aim_schema_type', $schema_type, $post ); $permalink = get_permalink( $post ); $data = array( '@context' => 'https://schema.org', '@type' => $schema_type, '@id' => $permalink, 'url' => $permalink, 'mainEntityOfPage' => $permalink, ); // Title: WebPage uses name, Article-like types use headline. $title = wp_strip_all_tags( get_the_title( $post ) ); if ( '' !== $title ) { if ( false !== stripos( $schema_type, 'page' ) ) { $data['name'] = $title; } else { $data['headline'] = $title; } } // Dates in ISO 8601 (respecting the site timezone). $published = get_post_time( 'c', false, $post ); $modified = get_post_modified_time( 'c', false, $post ); if ( $published ) { $data['datePublished'] = $published; } if ( $modified ) { $data['dateModified'] = $modified; } // Excerpt — manual only, to avoid duplicating the body and running auto-generation. if ( has_excerpt( $post ) ) { $excerpt = wp_strip_all_tags( get_the_excerpt( $post ) ); if ( '' !== $excerpt ) { $data['description'] = $excerpt; } } // Author. $author = get_the_author_meta( 'display_name', $post->post_author ); if ( is_string( $author ) && '' !== $author ) { $data['author'] = array( '@type' => 'Person', 'name' => $author, ); } // Cover image. $image = get_the_post_thumbnail_url( $post, 'full' ); if ( $image ) { $data['image'] = $image; } // Publisher (site) + logo from the site icon, if set. $publisher = array( '@type' => 'Organization', 'name' => get_bloginfo( 'name' ), 'url' => home_url( '/' ), ); $logo = get_site_icon_url( 512 ); if ( $logo ) { $publisher['logo'] = array( '@type' => 'ImageObject', 'url' => $logo, ); } $data['publisher'] = $publisher; // Post/site language. $lang = get_bloginfo( 'language' ); if ( '' !== $lang ) { $data['inLanguage'] = $lang; } /** * Final JSON-LD array (for extension by third-party code). * * @param array $data Schema.org data. * @param WP_Post $post Post. */ return (array) apply_filters( 'adg_aim_schema_data', $data, $post ); } }