Skip to content

Instantly share code, notes, and snippets.

@techlemur
Created February 11, 2019 21:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save techlemur/b4ee236e5f3726216060d0a12e376983 to your computer and use it in GitHub Desktop.
Save techlemur/b4ee236e5f3726216060d0a12e376983 to your computer and use it in GitHub Desktop.
get all available gutenberg block info for your site with javascript
/* Navigate to a wordpress edit page for any post and run one of the code sections below in a javascript console to get the names/info for all blocks available to gutenberg on your site. */
/* log all block info to console */
console.log(wp.data.select( "core/blocks" ).getBlockTypes());
/* log all block names to console */
wp.data.select( "core/blocks" ).getBlockTypes().forEach(function(element) {
console.log(element['name']);
});
/* print all block names to a new window */
var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top="+(screen.height-400)+",left="+(screen.width-840));
var tmpContent = 'Blocks<br><hr><br>';
wp.data.select( "core/blocks" ).getBlockTypes().forEach(function(element) {
tmpContent = tmpContent + element['name'] + "<br>";
});
win.document.body.innerHTML = tmpContent;
/* same thing but formatted for a php array with commented descriptions */
var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top="+(screen.height-400)+",left="+(screen.width-840));
var tmpContent = 'Block List<br><hr><br>array(<br>';
wp.data.select( "core/blocks" ).getBlockTypes().forEach(function(element) {
tmpContent = tmpContent + "'" + element['name'] + "', //"+element['description']+"<br>";
});
tmpContent = tmpContent + ');';
win.document.body.innerHTML = tmpContent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment