Notice: There is no legacy documentation available for this item, so you are seeing the current documentation.
Purpose
This filter can be used to filter the JSON schema that All in One SEO outputs.
Arguments (1)
- $graphs (array) – The graphs with their properties as multidimensional arrays.
Example code snippets
The code snippet below is just an example of how this filter can be used. In the example below, the BreadcrumbList graph is removed from the output.
add_filter( 'aioseo_schema_output', 'aioseo_filter_schema_output' );
function aioseo_filter_schema_output( $graphs ) {
foreach ( $graphs as $index => $graph ) {
if ( 'BreadcrumbList' === $graph['@type'] ) {
unset( $graphs[ $index ] );
}
foreach ( $graph as $key => $value ) {
if ( 'breadcrumb' === $key ) {
unset( $graphs[ $index ][ $key ] );
}
}
}
return $graphs;
}
The code snippet below is an example of how to remove the Article schema for Posts:
add_filter( 'aioseo_schema_output', 'aioseo_filter_schema_output' );
function aioseo_filter_schema_output( $graphs ) {
if ( is_singular( 'post' ) ) {
foreach ( $graphs as $index => $graph ) {
if ( 'Article' === $graph['@type'] ) {
unset( $graphs[ $index ] );
}
}
}
return $graphs;
}
The code snippet below shows how the datePublished
and dateModified
properties can removed from the Article schema for Posts:
add_filter( 'aioseo_schema_output', 'aioseo_filter_schema_output' );
function aioseo_filter_schema_output( $schema ) {
foreach ( $schema as $index => $graphData ) {
if ( empty( $graphData['@type'] ) ) {
continue;
}
$type = strtolower( $graphData['@type'] );
switch ( $type ) {
case 'article':
case 'blogposting':
case 'newsarticle':
unset( $schema[ $index ]['datePublished'] );
unset( $schema[ $index ]['dateModified'] );
break;
default:
break;
}
}
return $schema;
}
The code snippet below shows how the author of an article can be removed for Posts:
add_filter( 'aioseo_schema_output', 'aioseo_filter_schema_output' );
function aioseo_filter_schema_output( $graphs ) {
if ( is_singular( 'post' ) ) {
foreach ( $graphs as $index => $graph ) {
if ( 'Article' === $graph['@type'] ) {
unset( $graphs[ $index ]['author'] );
}
if ( 'Person' === $graph['@type'] ) {
unset( $graphs[ $index ] );
}
}
}
return $graphs;
}