## Block Editor: How to get title and post content within the WordPress admin UI in Javascript?

Question

Adapting some old SEO module (which was written for TinyMCE) I have to access the current post title and post content via JavaScript. I have been avoiding Gutenberg in the past, but it seems like this will be no longer possible.

Within the old SEO module there are the following lines in the admin.js:

var title = $('#title').val().trim(); var content =$('#content').val().trim();


Those fields do not exist in Gutenberg anymore. I have tried to find the correct way to do this in the docs, but no luck so far. I have found:

wp.data.select("core/editor").getBlocks()
wp.data.select("core")


But both seem to be empty arrays in my case (although this post has content). I basically just need a way to get the textual contents of all blocks (and maybe seperatly from the main post title if this is possible). Who knows how to do that?

0
2 years 2019-11-03T13:51:19-05:00 0 Answers 67 views 0