Modify post content before getting saved/updated in the database
-
I am trying to append an empty HTML tag at the end of the post content before it is saved to the database (if a new post) or updated (if an existing post). The
wp_insert_post_data
filter seemed like a good option, but when I tried it out I received an “Update failed” error message in the block editor.I’ve looked all over the forums and outside websites, but can’t seem to find a way to keep using this filter with Gutenberg. From what I’ve gathered, it has something to do with Gutenberg saving the post using the REST API. Regardless, what is a good approach to accomplish my goal?
Here is the code I was using that kept generating the error on Publish or Update. Note that even just trying to return the content without modifying it causes the “Update failed” error message.
add_filter( 'wp_insert_post_data', 'add_empty_span_tags_to_paragraph_blocks', 10, 2 ); public function add_empty_span_tags_to_paragraph_blocks( $data, $postarr ) { return $data; }
- The topic ‘Modify post content before getting saved/updated in the database’ is closed to new replies.