• I am two days in to make a custom dynamic block with PHP callback. Its basics are working! and now trying to clean up the style and size of the created element.

    My callback in PHP returns an iframe. This is the last line of the callback:

    return ‘<iframe width=800 height=800 src=”https://example.com/test.html”/&gt;

    and it does show the iframe in the view. However I think I need to add all properties that would be added in JS (by {…blockProps}) from the PHP callback to make the rendered block nicely formatted with the rest of content.

    How do I do it? Namely, I’d like to return the iframe with proper class names and id and other things in the blockProps.

    My registration function looks like this:

    function test_dynamic_init() {
        require_once(ABSPATH . 'wp-admin/includes/media.php');
        require_once(ABSPATH . 'wp-admin/includes/file.php');
        require_once(ABSPATH . 'wp-admin/includes/image.php');
    
        register_block_type( __DIR__ . '/build', array(
            'render_callback' => 'test_dynamic_render_callback'
        ) );
    }
    
    add_action( 'init', 'test_dynamic_init');
    

    and not have wp_register_script() call. Is it somehow the reason?

Viewing 2 replies - 1 through 2 (of 2 total)
  • This may not be the best method but my workaround is to create and save the class name and other block props as an attribute.

    I’m hoping that someone else has a better answer!

    Thread Starter Yoshiki Ohshima

    (@yoshikiohshima)

    Thanks. Looking at other blocks CSS classes in the default theme, only class I need seems to be is-layout-flex class so I added to a div element that now contains the iframe I actually want to show. As I wrote I was 2 days in (and now 3 days in) to WorldPress blocks programming so I can’t tell if this is fine for all other themes and things.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Access blockProps from render callback’ is closed to new replies.