JavaScript for WordPress Forums Gutenberg Development Dynamic block not showing in frontend Reply To: Dynamic block not showing in frontend

#45398
ataurr
Participant

I have added this to index.php but still nothing showing in front

function my_plugin_render_block_latest_post( $attributes ) {
    $recent_posts = wp_get_recent_posts( array(
        'numberposts' => 1,
        'post_status' => 'publish',
    ) );
    if ( count( $recent_posts ) === 0 ) {
        return 'No posts';
    }
    $post = $recent_posts[ 0 ];
    $post_id = $post['ID'];
    return sprintf(
        '<a class="wp-block-my-plugin-latest-post" href="%1$s">%2$s</a>',
        esc_url( get_permalink( $post_id ) ),
        esc_html( get_the_title( $post_id ) )
    );
}

function jsforwpblocks_register_blocks() {
    // Hook server side rendering into render callback
    register_block_type( 'gutenbergtest/dynamicblock', array(
        'render_callback' => 'my_plugin_render_block_latest_post',
    ) );

    register_meta( 'post', 'subheading', [
        'show_in_rest' => true,
    ] );

}

// Make sure that Gutenberg is available
if ( function_exists( 'register_block_type' ) ) {
    add_action( 'init', 'jsforwpblocks_register_blocks' );

}

I Am really confused what I am missing. I have searched on google nothing found any solution about this.

Its showing in editor

sergwers

Nothing showing in frontend

sdfserges