Last active
January 9, 2025 11:06
-
-
Save benpearson/3aed152100a03ba93cd5f5ce96c7c369 to your computer and use it in GitHub Desktop.
WordPress: Schema examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="application/ld+json"> | |
{ | |
"@context": "https://schema.org", | |
<?php | |
$post_id = dt_get_the_ID(); | |
if ( is_singular( 'ei_location' ) ) { | |
get_template_part('components/schema/location'); | |
} | |
elseif ( is_singular( 'ei_job' ) ) { | |
get_template_part('components/schema/job'); | |
} | |
elseif ( is_singular( 'ei_team_member' ) ) { | |
get_template_part('components/schema/person'); | |
} | |
elseif ( is_singular( 'post' ) && has_term( 'event', 'ei_post_type', $post_id ) ) { | |
get_template_part('components/schema/event'); | |
} | |
else { | |
get_template_part('components/schema/organisation'); | |
} | |
?> | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_id = dt_get_the_ID(); | |
$name = 'Client Name - ' . get_the_title($post_id); | |
$image_url = get_the_post_thumbnail_url($post_id, 'full'); | |
$url = get_permalink($post_id); | |
// Because date and time are strings that contain extra information we can use properties like startDate. Instead this information is added to the description. | |
$date = get_field( 'event_date', $post_id ); | |
$time = get_field( 'event_time', $post_id ); | |
$description = get_the_excerpt($post_id); | |
if ($date && $description) { | |
$description .= " | "; | |
} | |
if ($date) { | |
$description .= "Date: {$date}"; | |
} | |
if ($time && $description) { | |
$description .= " | "; | |
} | |
if ($time) { | |
$description .= "Time: {$time}"; | |
} | |
$location = get_field( 'event_location', $post_id ); | |
?> | |
"@type": "Event", | |
"name": "<?= $name ?>", | |
"image": "<?= $image_url ?>", | |
"url": "<?= $url ?>", | |
"description": "<?= $description ?>", | |
"location": "<?= $location ?>", | |
"organizer": { | |
<?php get_template_part('components/schema/organisation'); ?> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_id = dt_get_the_ID(); | |
$title = html_entity_decode(get_the_title($post_id)); | |
$description = dt_get_clean_job_excerpt($post_id); | |
$url = get_permalink($post_id); | |
// Application URL with query string for form pre-population | |
$contactPointURL = add_query_arg([ | |
'jobtitle' => html_entity_decode(get_the_title()), | |
'jobadder_ad_id' => get_field('id') | |
], get_site_url() . '/work-with-us/current-opportunities/apply/'); | |
// Dates in ISO 8601 format | |
$date_posted_raw = get_field('date_posted', $post_id); | |
$datePosted = dt_convert_date_to_iso_8601($date_posted_raw); | |
$date_closing_raw = get_field('date_closing', $post_id); | |
$validThrough = dt_convert_date_to_iso_8601($date_closing_raw); | |
$employmentType = dt_get_string_of_terms($post_id, 'employment_term'); | |
$jobLocation = dt_get_string_of_terms($post_id, 'job_location', ' – '); | |
$occupationalCategory = dt_get_string_job_categories($post_id, '==='); // Top level categories | |
$relevantOccupation = dt_get_string_job_categories($post_id, '!=='); // Sub categories | |
?> | |
"@type": "JobPosting", | |
"title": "<?= $title ?>", | |
"description": "<?= $description ?>", | |
"url": "<?= $url ?>", | |
"hiringOrganization": { | |
<?php get_template_part('components/schema/organisation'); ?> | |
}, | |
"applicationContact": { | |
"@type" : "ContactPoint", | |
"url" : "<?= $contactPointURL ?>" | |
}, | |
"datePosted": "<?= $datePosted ?>", | |
"validThrough": "<?= $validThrough ?>", | |
"employmentType": "<?= $employmentType ?>", | |
"jobLocation": "<?= $jobLocation ?>", | |
"occupationalCategory": "<?= $occupationalCategory ?>", | |
"relevantOccupation": "<?= $relevantOccupation ?>", | |
"directApply": "True" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_id = dt_get_the_ID(); | |
$name = 'Client Name - ' . get_the_title($post_id); | |
$streetAddress = trim(get_field('address', $post_id)); // Should only be street address but this contains suburb, state and postcode | |
$openingHours = trim(get_field('operating_hours', $post_id)); | |
$url = get_permalink($post_id); | |
$phone = trim(get_field('phone', $post_id)); | |
$description = strip_tags(get_field('description', $post_id)); | |
$directions_url = trim(get_field('directions_url', $post_id)); | |
$state_term_obj = get_the_terms($post_id, 'state'); | |
$addressRegion = ($state_term_obj) ? $state_term_obj[0]->name : ''; // Only uses first state term if multiple are assigned | |
?> | |
"@type": "LocalBusiness", | |
"address": "<?= $streetAddress ?>", | |
"name": "<?= $name ?>", | |
"openingHours": "<?= $openingHours ?>", | |
"telephone": "<?= $phone ?>", | |
"url": "<?= $url ?>", | |
"description": "<?= $description ?>", | |
"hasMap": { | |
"@type": "Map", | |
"url": "<?= $directions_url ?>" | |
}, | |
"parentOrganization": { | |
<?php get_template_part('components/schema/organisation'); ?> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$organisation_data = dt_get_organisation_data(); | |
extract($organisation_data); | |
?> | |
"@type": "Organization", | |
"name": "<?= $name ?>", | |
"url": "<?= $url ?>", | |
"logo": "<?= $logoURL ?>", | |
"description": "<?= $description ?>", | |
"telephone": "<?= $telephone ?>", | |
"sameAs": [ | |
"https://www.facebook.com/client/", | |
"https://www.instagram.com/client/", | |
"https://www.youtube.com/channel/key", | |
"https://au.linkedin.com/company/client" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_id = dt_get_the_ID(); | |
$name = 'Client Name - ' . get_the_title($post_id); | |
$url = get_the_permalink($post_id); | |
$image_url = get_the_post_thumbnail_url($post_id, 'full'); | |
$jobTitle = get_field('position', $post_id); | |
?> | |
"@type": "Person", | |
"name": "<?= $name ?>", | |
"image": "<?= $image_url ?>", | |
"url": "<?= $url ?>", | |
"jobTitle": "<?= $jobTitle ?>", | |
"worksFor": { | |
<?php get_template_part('components/schema/organisation'); ?> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment