Register custom navigation block
-
I’m working on a custom menu block. The block itself is working fine, including appearing in the WordPress editor, but I’ve just noticed this message in the Dev Tools console ‘Block with API version 2 or lower is deprecated since version 6.9’
This is block.json:
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "ncvp/header-menu",
"title": "NCVP 2017-style header menu",
"category": "theme",
"icon": "menu",
"description": "Works in 2025 child theme",
"supports": {
"html": false
},
"editorScript": "file:./editor.js"
}This is editor.js:
(function(blocks, element) {
var el = element.createElement;
blocks.registerBlockType('ncvp/header-menu', { // xxxx/yyyy matches header.html
edit: function() {
return el('div', {
style: {
padding: '20px',
background: '#f0f0f0',
border: '5px solid #0073aa',
textAlign: 'center',
borderRadius: '10px'
}
},
[el('span', {}, 'NCVP header menu derived from Twenty Seventeen')]
);
},
save: function() {
return null;
}
});
})(window.wp.blocks, window.wp.element);and this is the call in functions.php:
function t17m_enqueue_editor_script() {
wp_enqueue_script(
't17m-block-editor',
get_stylesheet_directory_uri() . '/t17m/editor.js',
array('wp-blocks', 'wp-element'),
filemtime(get_stylesheet_directory() . '/t17m/editor.js')
);
}
add_action('init', 't17m_enqueue_editor_script');Can anyone please advise what I should do to conform to current standards?
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
You must be logged in to reply to this topic.