Add Person Schema to Author Page

Home » Snippets » Add Person Schema to Author Page
0

Created with:

Visibility: 

public

Creator: Jules Webb

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php

add_filter( 'wds_schema_printer_schema_data', 'wpturbo_add_custom_markup', 10, 2 );

function wpturbo_add_custom_markup( $data, $entity ) {
    if ( ! ( $entity instanceof SmartCrawlEntitiesPost_Author ) ) {
        return $data; // Not a Post Author archive.
    }

    // Add the URL condition here
    $request_uri = $_SERVER['REQUEST_URI'];
    if ( strpos( $request_uri, '/author/alana-holst' ) !== false ) {
        // Edit the following:
        $custom_markup = [
            "@context" => "https://schema.org/",
            "@type"    => "Person",
            "name"     => "Peter Venkman",
            "hasOccupation" => [
                "@type" => "Occupation",
                "name"  => "Parapsychologist",
                "educationRequirements" => "PhD in parapsychology"
            ]
        ];

        $data[] = $custom_markup;
    }

    return $data;
}
				

In this updated code, we retrieve the current URL using $_SERVER['REQUEST_URI'] and check if it contains the string '/author/alana-holst'. If it does, the custom markup is added to the $data array.

Please replace the existing code in the 'wp-plugin.php' file with this updated code.

Let me know if you have any further questions!

Register an account to save your snippets or go Pro to get more features.