Enhancing structured data
-
I want to post this for two reasons. Firstly, there may be some SEOers out there who want to enhance their structured schema on some of their AMP pages. After all Google is encouraging that AMP and canonical pages have the same structured markup where possible.
Secondly to encourage the plugin developers to solve the general problem which only requires a scripts to footer box in admin per page and the ability to set the page type on a per page basis. It then avoids this type of coding below.
Here we go …
This code to be placed in functions.php will put the specific page type into the structured data. Obviously your about page may not be ‘about-us’ but just called ‘about’ or ‘who-are-we’ etc. Same for your contact page. If you try this code and then use the structured data tester you will see it is no longer the generic Webpage for those pages but the more specific type.
function ampforwp_structured_data( $metadata ){ if( is_page( 'about-us' ) ){ $metadata['@type'] = 'AboutPage'; } if( is_page( 'contact' ) ){ $metadata['@type'] = 'ContactPage'; } return $metadata; } add_filter( 'amp_post_template_metadata', 'ampforwp_structured_data', 22, 1 );
The second part of the structured data enhancment is to embed specific entities like a local business but it could equally be reviews or events. Here I insert local business structured data into the home page which happens to be static and the about us page.
function amp_schema_special() { if(ampforwp_is_front_page()) { ?> <script type="application/ld+json"> { "@context" : "https://schema.org", "@type" : "localBusiness", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://www.blabla.com/" }, "address" : { "@type": "PostalAddress", "addressLocality": "ffffff", "addressCountry": "ffffffffffff", "postalCode": "999999", "streetAddress": "your long address" }, "name":"Blabla Things", "alternateName": [ "Blabla items" ], "legalName": "blabalski", "brand": "blas", "description" : "a nice long description of your local business", "email":"[email protected]", "telephone":"+99 999991", "openingHours": [ "Mo,Tu,We,Th,Fr,Sa,Su, 08:45-12:00, 14:00-18:00" ], "pricerange": "$$", "geo": { "@type": "GeoCoordinates", "latitude": "0.000888", "longitude": "6.666688" }, "logo": "https://www.blabla.com/wp-content/uploads/2017/09/logo.png", "Image": "https://www.blabla.com/wp-content/uploads/2017/04/picture.jpg", "sameAs" : [ "https://www.facebook.com/blabla", "https://plus.google.com/6666666667896/", "https://www.youtube.com/channel/fffffffsdfqf", "https://twitter.com/blabla" ], "url":"https://www.www.blabla.com/" } </script> <?php } if (is_page('about-us') && is_amp_endpoint()) { ?> <script type="application/ld+json"> { "@context" : "https://schema.org", "@type" : "localBusiness", "additionalType":"https://www.productontology.org/id/Ski_school", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://www.blabla.com/about-us/" } . . . <?php } } add_action( 'amp_post_template_footer', 'amp_schema_special');
- The topic ‘Enhancing structured data’ is closed to new replies.