Skip to content
Discussion options

You must be logged in to vote

You've actually self-diagnosed it correctly — the reason is in how block.json's render field is implemented in core. Looking at wp-includes/blocks.php, when register_block_type_from_metadata() sees a render field in block.json, it doesn't call a function — it generates an internal render_callback that does:

ob_start();
require $template_path;
return ob_get_clean();

So render.php is expected to output HTML directly (echo / inline markup / function call). It's not a place to define a function — anything just defined there gets loaded at render time and discarded.

On top of that you're also passing 'render_callback' => 'my_namespace_render' to register_block_type() as a string reference. At i…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Der-Alex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants