Home / Admin / Add missing mainEntity to ProfilePage Schema
Duplicate Snippet

Embed Snippet on Your Site

Add missing mainEntity to ProfilePage Schema

This snippet adds missing mainEntity to ProfilePage Schema

<10
Code Preview
php
<?php
add_filter( 'aioseo_schema_output', function ( $schema ) {
	foreach ( $schema as &$schemaItem ) {
		if (
			empty( $schemaItem['mainEntity'] ) &&
			isset( $schemaItem['@type'] ) &&
			'ProfilePage' === $schemaItem['@type']
		) {
			global $wp;
			$current_url              = untrailingslashit( home_url( $wp->request ) );
			$schemaItem['mainEntity'] = [
				'@id' => $current_url . '/#author'
			];
		}
	}
	return $schema;
} );

Comments

Add a Comment