← AnchorageList.com
Developer Reference

LocalBusiness Schema Markup β€” Setup Guide

This page documents the JSON-LD schema code that should be added to the site. Since the Code Snippets plugin is not currently active, please add this to your child theme’s functions.php file or install the Code Snippets plugin.

<?php
// AnchorageList LocalBusiness Schema β€” add to child theme functions.php or Code Snippets plugin
add_action('wp_head', function() {
    if (!is_singular('hp_listing')) return;
    global $post;
    $listing_id = $post->ID;
    $title = get_the_title($listing_id);
    $desc = wp_strip_all_tags(get_the_excerpt($listing_id));
    if (!$desc) $desc = wp_strip_all_tags(substr(get_the_content(null, false, $post), 0, 200));
    $address = get_post_meta($listing_id, 'hp_location', true);
    if (!$address) $address = get_post_meta($listing_id, 'hp_address', true);
    $phone = get_post_meta($listing_id, 'hp_phone', true);
    $website = get_post_meta($listing_id, 'hp_website', true);
    $image = get_the_post_thumbnail_url($listing_id, 'large');
    $terms = get_the_terms($listing_id, 'hp_listing_category');
    $category = ($terms && !is_wp_error($terms)) ? $terms[0]->name : 'Local Business';
    $schema = [
        '@context' => 'https://schema.org',
        '@type' => 'LocalBusiness',
        'name' => $title,
        'description' => $desc,
        'address' => [
            '@type' => 'PostalAddress',
            'streetAddress' => $address,
            'addressLocality' => 'Anchorage',
            'addressRegion' => 'AK',
            'addressCountry' => 'US'
        ],
    ];
    if ($phone) $schema['telephone'] = $phone;
    if ($website) $schema['url'] = $website;
    if ($image) $schema['image'] = $image;
    $json = json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    echo '<script type="application/ld+json">' . $json . '</scr' . 'ipt>' . "\n";
}, 10);

// BreadcrumbList on taxonomy pages
add_action('wp_head', function() {
    if (!is_tax('hp_listing_category')) return;
    $term = get_queried_object();
    if (!$term) return;
    $schema = [
        '@context' => 'https://schema.org',
        '@type' => 'BreadcrumbList',
        'itemListElement' => [
            ['@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => home_url('/')],
            ['@type' => 'ListItem', 'position' => 2, 'name' => 'Listings', 'item' => home_url('/listings/')],
            ['@type' => 'ListItem', 'position' => 3, 'name' => $term->name, 'item' => get_term_link($term)],
        ]
    ];
    $json = json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    echo '<script type="application/ld+json">' . $json . '</scr' . 'ipt>' . "\n";
}, 10);

What This Does

  • Adds LocalBusiness JSON-LD schema to every HivePress listing page
  • Pulls business name, description, address, phone, website, and featured image
  • Adds BreadcrumbList schema to category/taxonomy pages
  • Helps Google display rich results in search

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.