Schema Article Builder
Builds JSON-LD data for article/tutorial style pages.
Function signature
ogBuildArticleSchemaData(title, description, url, options = array())
Categories
- Database Integrity
Parameters
titleHuman-facing title used for metadata, schema, or alt text.descriptionPlain-text description used for Open Graph or schema output.urlCanonical URL associated with the generated metadata or schema.optionsOptional documented policy controls for the helper.Return value
Public-safe status string returned by the function for controller branching or logging.
- success
- message
- data
Compatibility
Existing function name, slug, path, and call order preserved; advertised metadata corrected to the actual source behavior.
Minimum PHP version: 7.4
Security notes
Use caller-owned allowlists and context-specific escaping; validate file paths, routes, email tokens, cart totals, discount rules, and tax-region rules before production use.
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Builds JSON-LD data for article/tutorial style pages.
*
* Primary use case: Structured data for tutorials/resources.
* Typical inputs: title, author, dates, URL, description.
* Typical output: schema array.
*
* Implementation note: Validate with search tools before deploy.
*
* @return array Structured result data with success, message, and data keys.
*/
function ogBuildArticleSchemaData($title, $description, $url, $options = array()) {
$result = array(
'success' => false,
'message' => '',
'data' => array()
);
$title = trim(strip_tags((string)$title));
$description = trim(strip_tags((string)$description));
$url = trim((string)$url);
if (!is_array($options)) {
$options = array();
}
if (empty($title) || empty($url)) {
$result['message'] = 'Article schema requires a title and URL.';
return $result;
}
if (!preg_match('/^(\/\/|https:\/\/)/i', $url)) {
$result['message'] = 'Article URL must be protocol-relative or HTTPS.';
return $result;
}
$author = 'PHPOG';
if (!empty($options['author'])) {
$author = trim(strip_tags((string)$options['author']));
}
$date_published = '';
if (!empty($options['date_published'])) {
$date_published = trim((string)$options['date_published']);
}
$date_modified = $date_published;
if (!empty($options['date_modified'])) {
$date_modified = trim((string)$options['date_modified']);
}
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Article',
'headline' => $title,
'description' => $description,
'url' => $url,
'author' => array(
'@type' => 'Person',
'name' => $author
)
);
if (!empty($date_published)) {
$schema['datePublished'] = $date_published;
}
if (!empty($date_modified)) {
$schema['dateModified'] = $date_modified;
}
$result['success'] = true;
$result['message'] = 'Article schema data built.';
$result['data'] = array('schema' => $schema);
return $result;
}