Modify/Extend code not working
-
I’m using the code from https://schema.press/docs/extend-schema-output/ in my functions and it isn’t modifying the schema output.
In fact, if I remove conditionals and just use the filter to echo a string the string is not echoed; it’s like the filter isn’t being applied at all.
The plugin is working as expected and the standard schema json is present in the page source. Example page
I do know the PHP is being loaded because if I malform the PHP the page throws a PHP error. The PHP is loaded but filter not applied.
I’ve tried using the code verbatim and also modified it for my testing. Here’s the modified version:
add_filter( 'schema_output', 'to4_modify_schema' ); function to4_modify_schema( $schema ) { global $post; // Test debug. 'Foobar' is not present in the markup. echo '<pre> foobar'; var_dump( $schema ); echo '</pre>'; if ( empty( $schema ) ) return; // Debug echo '<pre>'; print_r( $schema ); echo '</pre>'; // Modify NewType to present the actual schema.org type // if ( $schema['@type'] != 'NewsArticle' ) return $schema; // Modify / Override values $schema['title'] = 'Foobar'; // Add new values // $schema['name'] = 'Event Name'; // Unset extras unset( $schema['author'] ); // unset($schema['ArticleSection']); return $schema; }
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Modify/Extend code not working’ is closed to new replies.