Title: Modify/Extend code not working
Last modified: August 2, 2018

---

# Modify/Extend code not working

 *  [slamorte](https://wordpress.org/support/users/slamorte/)
 * (@slamorte)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/)
 * I’m using the code from [https://schema.press/docs/extend-schema-output/](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](https://truthout.org/articles/the-border-fetish-the-us-frontier-as-a-zone-of-profit-and-sacrifice/)
 * 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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fmodify-extend-code-not-working%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Hesham Zebida](https://wordpress.org/support/users/hishaman/)
 * (@hishaman)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10557137)
 * I think the reason why the filter isn’t working is that Schema plugin still reads
   the old data which is saved in post meta, or maybe your pages are cached.
 * Can you try saving the plugin settings once, then check if this solves the issue.
   Also, if you are running a cache plugin try delete cache.
 *  Thread Starter [slamorte](https://wordpress.org/support/users/slamorte/)
 * (@slamorte)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10557175)
 * Thanks for the quick reply.
 * It doesn’t work on my localhost (MAMP server, Webpack, yarn) which doesn’t do
   any caching.
 * I have saved the plugin settings, upgraded from 1.6.x to 1.7, and turning Use
   Yoast Schema off and on, thinking there might be a conflict.
 * Oddly enough it does seem to work when I publish the code to my production site.
   I pushed only `unset( $schema['author'] );` code to the production server and
   the author field does seem suppressed on [this article page.](http://view-source:https://truthout.org/articles/mueller-is-building-a-case-for-obstruction-manafort-may-be-the-key/)
 * This makes it hard to develop and test customizations, but at least it works.
 * Any thoughts on why it wouldn’t work locally?
    -  This reply was modified 7 years, 9 months ago by [slamorte](https://wordpress.org/support/users/slamorte/).
 *  Thread Starter [slamorte](https://wordpress.org/support/users/slamorte/)
 * (@slamorte)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10569092)
 * Hi again,
 * Yes, it’s the post_meta.
 * I checked the post_meta field and the custom schema is written to post_meta the
   first time the schema modify code is used. If the modification code uses `$schema['
   author'] = 'foo'`, then `"Author":"Foo"` is written to post_meta.
 * However, modifying the code and reloading the page does not rewrite the post_meta
   field. Schema is pulling the post_meta version of the schema rather than rebuilding
   it from the updated code. If I update the code to `$schema['author'] = 'bar'`,
   and reload the page, `"Author":"Foo"` is still displayed.
 * I can delete the post_meta entry and reload the page and see the updated results,
   but this make testing and development rather slow.
 * The modification code may need an additional function that removes the post_meta
   or expires the post_meta (I see there is a `_schema_json_timestamp` field which
   I assume is used to expire the `_schema_json`)
 *  Plugin Author [Hesham Zebida](https://wordpress.org/support/users/hishaman/)
 * (@hishaman)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10605196)
 * I understand what you mean.. Yes, the saved _schema_json post meta value expires
   after 24 hours.
 * Also it got deleted on some occasions, example:
 * – If you updated the post.
    – If a new comment is submitted on a post. – If you
   update Schema -> Type. – If you updated the plugin settings.
 * So, maybe update the post or plugin settings will come more handy when developing.
 *  Thread Starter [slamorte](https://wordpress.org/support/users/slamorte/)
 * (@slamorte)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10607483)
 * Thanks Hesham!
 * Those are some good workaround to this issue. Now that I know what the issue 
   is I can probably figure out other workarounds.
 * If I could request a feature it would be for a function that forces schema updates
   sitewide during development. Something like:
 * `force_schema_cache_rebuild()`
 * Or optionally force it on one post:
 * `force_schema_cache_rebuild( post_id )`
 * There is a WordPress function that would work for a single post at ID 1234:
 * `delete_post_meta( 1234, '_schema_json_timestamp' );`
 * A variant of that might work for a more general schema cache clearing:
 *     ```
       function force_schema_cache_rebuild {
         $post_id = get_the_ID();
         if( ! empty( $post_id ) {
           delete_post_meta( get_the_ID(), '_schema_json_timestamp' );
         }
       }
       ```
   
 * But I have not tested this.
 * I just finished writing code that populates `$schema['author']` with multiple
   authors from an ACF relationship field. It works great but took ages to test 
   without a schema cache clear during the 20 or so revisions it took me to get 
   it rights.
 * Thanks again for a great plugin!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Modify/Extend code not working’ is closed to new replies.

 * ![](https://ps.w.org/schema/assets/icon-256x256.png?rev=1750173)
 * [Schema](https://wordpress.org/plugins/schema/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/schema/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/schema/)
 * [Active Topics](https://wordpress.org/support/plugin/schema/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/schema/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/schema/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)

 * 5 replies
 * 2 participants
 * Last reply from: [slamorte](https://wordpress.org/support/users/slamorte/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/modify-extend-code-not-working/#post-10607483)
 * Status: not resolved