Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Created April 24, 2023 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanpariyar/c31889716cefaa9dec24a40e0beb086f to your computer and use it in GitHub Desktop.
Save vanpariyar/c31889716cefaa9dec24a40e0beb086f to your computer and use it in GitHub Desktop.
Register callback for dynamic block from PHP

Try This one on your functions.php or main Plugin file

add_filter('register_block_type_args', function ($settings, $name) {
    if ($name == 'demo/content-with-sidebar') {
        $settings['render_callback'] = 'demo_blocks_content_with_sidebar';
    }
    return $settings;
}, null, 2);

replace your block name with demo/content-with-sidebar here demo is the block name space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment