1-Byte
1-Byte Bespoke tools & code

PHP + JSON

JSON-LD Website Schema Block

PHP + JSON

Outputs a JSON-LD block with Website and Organisation information. Helps search engines understand what the site is and who is behind it.

Usage notes

Place this near the end of your <head> element. Adjust name, URL and logo to match your brand.

Copy this snippet into your project

Use the full version for learning, or copy it without comments when you just want the bare code.

<?php
$schema = [
    '@context' => 'https://schema.org',
    '@graph'   => [
        [
            '@type' => 'Organization',
            'name'  => 'Your Brand Name',
            'url'   => 'https://example.com',
            'logo'  => 'https://example.com/assets/logo.png',
        ],
        [
            '@type'        => 'WebSite',
            'name'         => 'Your Brand Name',
            'url'          => 'https://example.com',
            'potentialAction' => [
                '@type'       => 'SearchAction',
                'target'      => 'https://example.com/search?q={search_term_string}',
                'query-input' => 'required name=search_term_string',
            ],
        ],
    ],
];
?>
<script type="application/ld+json">
<?= json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n" ?>
</script>
      

Tags

#seo #json-ld #schema #search
← Back to all snippets