Calling “render_callback” inside “register_block_type” in OOP
-
I’ve followed several tutorials explaining how to get started with server-side blocks and all of them use
render_callback
inside of theregister_block_type()
function. I have been able to get it to appear in the editor, but when I view the post on the front-end the block doesn’t appear.I know it has nothing to do with the code *inside* the function because I’m simply returning a hard-coded
<p>
tag immediately.I thought maybe it was because I was trying it inside of an object-oriented class (trait to be specific), so I tried doing it procedurally and it worked. Now I need to get it to work with OOP, but I can’t tell if it’s where the function is called or how I’m calling it…
Here’s are my two functions.
gutenberg_latest_posts_block
is being hooked atinit
(not shown). Again, this is working in the editor, but not the front-end.public function gutenberg_latest_posts_block(){ //Editor Script wp_register_script( 'nebula-latest-posts-block', get_template_directory_uri() . '/libs/Gutenberg/blocks/latest/latest.js', array('wp-blocks', 'wp-element') ); register_block_type('nebula/latest-posts', array( 'editor_script' => 'nebula-latest-posts-block', 'render_callback' => 'nebula_get_latest_post', //Not working. Also tried array($this, 'nebula_get_latest_post') )); } //Function for the front-end //Tried moving this outside of the class, but no luck there either. public function nebula_get_latest_post($attributes){ echo '<h1>testing</h1>'; return 'this would be posts! yay!'; //this never appears }
- The topic ‘Calling “render_callback” inside “register_block_type” in OOP’ is closed to new replies.