DEV Community

Cover image for WordPress ScholarlyArticle JSON-LD Schema (PHP Guide)
Istiak Ahamed
Istiak Ahamed

Posted on Originally published at kinetix.software

WordPress ScholarlyArticle JSON-LD Schema (PHP Guide)

WordPress ScholarlyArticle JSON‑LD Schema (PHP Guide)

In the world of academic publishing, the ability to expose a post as a ScholarlyArticle via JSON‑LD is essential for visibility in search engines and academic databases. Yet most WordPress installations rely on generic schema plugins that miss the DOI, Highwire tags, and other metadata required by Google Scholar and Crossref. This guide shows how to build a lightweight, production‑ready solution that outputs a fully compliant ScholarlyArticle schema, including DOI and Highwire tags, without any jQuery or heavy dependencies.

Table of Contents

Prerequisites

  • WordPress 6.5 or newer.
  • PHP 8.2 or newer.
  • Basic understanding of WordPress hooks, shortcodes, and admin screens.
  • Optional: A child theme or a site‑wide plugin to house the code.

Design Overview

The solution follows a clear separation of concerns:

  1. Data Retrieval – Pull post meta and taxonomy terms.
  2. Schema Construction – Build a PHP array that maps to JSON‑LD.
  3. Output – Echo the schema in the <head> via wp_head hook.
  4. Admin UI – Allow authors to enter DOI and Highwire tags.

All interactions are performed server‑side; no JavaScript is required for rendering the schema.


Mermaid Flowchart: Data & Render Pipeline

flowchart TD
    A[WordPress Post] --> B[Retrieve Meta & Taxonomy]
    B --> C[Build PHP Array]
    C --> D[Encode JSON‑LD]
    D --> E[Inject into <head>]
    E --> F[Browser Receives JSON‑LD]

Implementing the Schema Generator

Core Function

Create a file inc/schema-scholar.php in your plugin or theme and add the following:

<?php
declare(strict_types=1);
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'kinetix_scholar_generate_schema' ) ) {
    /**
     * Generate ScholarlyArticle JSON‑LD for the current post.
     *
     * @param int $post_id Post ID.
     * @return array|null
     */
    function kinetix_scholar_generate_schema( int $post_id ): ?array {
        if ( ! get_post( $post_id ) ) {
            return null;
        }

        // Basic post data
        $post = get_post( $post_id );
        $schema = [
            '@context' => 'https://schema.org',
            '@type'    => 'ScholarlyArticle',
            'headline' => wp_strip_all_tags( $post->post_title ),
            'datePublished' => get_the_date( 'c', $post ),
            'author' => [],
            'publisher' => [
                '@type' => 'Organization',
                'name' => get_bloginfo( 'name' ),
            ],
        ];

        // Authors
        $authors = get_the_author_meta( 'display_name', $post->post_author );
        if ( $authors ) {
            $schema['author'][] = [
                '@type' => 'Person',
                'name' => sanitize_text_field( $authors ),
            ];
        }

        // DOI
        $doi = get_post_meta( $post_id, '_scholar_doi', true );
        if ( $doi ) {
            $schema['identifier'] = [
                '@type' => 'PropertyValue',
                'propertyID' => 'doi',
                'value' => esc_url_raw( $doi ),
            ];
            $schema['url'] = esc_url_raw( $doi );
        }

        // Highwire tags
        $highwire = [
            'highwire:doi' => $doi,
            'highwire:publication_date' => get_the_date( 'Y-m-d', $post ),
            'highwire:article_title' => wp_strip_all_tags( $post->post_title ),
        ];
        foreach ( $highwire as $key => $value ) {
            if ( $value ) {
                $schema[$key] = sanitize_text_field( $value );
            }
        }

        // Keywords
        $tags = wp_get_post_tags( $post_id, [ 'fields' => 'names' ] );
        if ( $tags ) {
            $schema['keywords'] = implode( ', ', $tags );
        }

        return $schema;
    }
}
Enter fullscreen mode Exit fullscreen mode

Shortcode Integration

Add a shortcode to allow authors to embed the schema manually if needed:

if ( ! function_exists( 'kinetix_scholar_schema_shortcode' ) ) {
    function kinetix_scholar_schema_shortcode( $atts ) {
        $post_id = get_the_ID();
        $schema = kinetix_scholar_generate_schema( $post_id );
        if ( ! $schema ) {
            return '';
        }
        return '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . '</script>';
    }
    add_shortcode( 'scholar_schema', 'kinetix_scholar_schema_shortcode' );
}
Enter fullscreen mode Exit fullscreen mode

Admin Settings Page

Provide a simple meta box for DOI entry:

if ( ! function_exists( 'kinetix_scholar_meta_box' ) ) {
    function kinetix_scholar_meta_box() {
        add_meta_box(
            'scholar_meta_box',
            'Scholarly Article Settings',
            'kinetix_scholar_meta_box_callback',
            'post',
            'side',
            'default'
        );
    }
    add_action( 'add_meta_boxes', 'kinetix_scholar_meta_box' );
}

function kinetix_scholar_meta_box_callback( $post ) {
    $doi = get_post_meta( $post->ID, '_scholar_doi', true );
    wp_nonce_field( 'kinetix_scholar_save_meta', 'kinetix_scholar_meta_nonce' );
    ?>
    <label for="scholar_doi">DOI:</label>
    <input type="text" id="scholar_doi" name="scholar_doi" value="<?php echo esc_attr( $doi ); ?>" style="width:100%;" />
    <?php
}

if ( ! function_exists( 'kinetix_scholar_save_meta' ) ) {
    function kinetix_scholar_save_meta( $post_id ) {
        if ( ! isset( $_POST['scholar_doi'] ) ) {
            return;
        }
        if ( ! wp_verify_nonce( $_POST['kinetix_scholar_meta_nonce'], 'kinetix_scholar_save_meta' ) ) {
            return;
        }
        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return;
        }
        $doi = sanitize_text_field( $_POST['scholar_doi'] );
        update_post_meta( $post_id, '_scholar_doi', $doi );
    }
    add_action( 'save_post', 'kinetix_scholar_save_meta' );
}
Enter fullscreen mode Exit fullscreen mode

Injecting into the Head

Hook the schema output into wp_head:

if ( ! function_exists( 'kinetix_scholar_output_schema' ) ) {
    function kinetix_scholar_output_schema() {
        if ( ! is_singular( 'post' ) ) {
            return;
        }
        $post_id = get_the_ID();
        $schema = kinetix_scholar_generate_schema( $post_id );
        if ( ! $schema ) {
            return;
        }
        echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . '</script>' . PHP_EOL;
    }
    add_action( 'wp_head', 'kinetix_scholar_output_schema' );
}
Enter fullscreen mode Exit fullscreen mode

Comparison Tables

Feature Comparison: Kinetix Scholar vs Legacy Plugins

Feature Kinetix Scholar (Custom Code) Generic Schema Plugin Highwire‑Specific Plugin
DOI Support ✔︎ ❌ ✔︎
Highwire Tags ✔︎ ❌ ✔︎
Custom Meta Fields ✔︎ ❌ ❌
Admin UI Simple meta box Full settings panel Full settings panel
Dependency Footprint 0 KB JS 120 KB 80 KB
Update Frequency 1‑2 releases per year 3‑4 releases per year 1 release per year
Compatibility WP 6.5+ WP 4.9+ WP 5.0+

Pricing & Feature Matrix

Product Price Lifetime Support Features
Kinetix Scholar & SEO Pro $199 Lifetime Email DOI, Highwire, Google Scholar meta tags, SEO audit
UiCore PRO $499 Lifetime Phone Full schema support, eCommerce, analytics
Legacy Schema Plugin $0 Free None Basic Article schema, no DOI
Highwire‑Specific Add‑on $99 One‑time Email Highwire tags only

Verification & Troubleshooting

Check JSON‑LD Output in the Browser

Open the page source and locate the JSON‑LD script tag


{
  "@context":"https://schema.org",
  "@type":"ScholarlyArticle",
  ...
}

Enter fullscreen mode Exit fullscreen mode

If the script is missing, confirm the wp_head hook is active and the post is singular.

Validate DOI and Highwire Tags

Use Crossref API to verify DOI resolution

curl -s https://api.crossref.org/works/10.1234/abcd | jq .
Enter fullscreen mode Exit fullscreen mode

The response should contain message.title, message.author, and message.issued.

If the DOI does not resolve, double‑check the value entered in the meta box.


Zero‑Maintenance Alternative: Kinetix Scholar & SEO Pro

If writing and maintaining custom code is not ideal, the Kinetix Scholar & SEO Pro package offers a plug‑and‑play solution. It automatically injects a fully compliant ScholarlyArticle schema, handles DOI and Highwire tags, and includes additional Google Scholar meta tags. No JavaScript, no jQuery, and no manual updates.

Explore the product at /products/scholar-seo-pro or view the pricing details at /pricing.


Next Steps: Google Scholar Meta Tags

After ensuring the JSON‑LD is correct, you may want to add traditional meta tags for Google Scholar. The Kinetix blog post on WordPress Google Scholar meta tags provides a concise guide on adding <meta name="citation_doi" content="..."> and related tags.


Final Thoughts

By following this PHP‑centric approach, you can expose every scholarly post on your WordPress site with the full set of required metadata. The solution is lightweight, secure, and fully compliant with the latest schema.org specifications. Whether you choose to implement the code yourself or opt for the Kinetix Scholar & SEO Pro package, your content will be ready for discovery by academic search engines and indexing services.

Related Guides


Originally published at https://kinetix.software/blog/wordpress-scholarly-article-json-ld-schema.

Top comments (0)