Support » Developing with WordPress » How to get all attributes of a block in PHP?

  • More detailed explanation on my situation here:

    I found out that not all attributes in Javascript are passed to PHP, when I override a core block with the following code.

    function reregister_image_block(){
        register_block_type( 'core/image', array(
    		'render_callback' => 'override_image_block_output',
    	) );
    add_action('init', 'reregister_image_block');
    function override_image_block_output ($attributes, $content){
    //Override the block

    Why are some attributes not pass? How can I pass all attributes or pass attributes selectively to PHP?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Tyler


    Hi there,

    Is there any particular reason you’re using PHP for obtaining the attributes? If not, then I’d recommend using JavaScript since this is the foundational language of Gutenberg and it makes working with blocks much easier. This article here may help you with what you’re looking for.


    Thread Starter kghugo2000


    Hi Tyler,

    The main reason I want to override a default block in PHP is the avoiding breaking the original block in the editor. I don’t want to create new image block again for each of my post.

    And for my personal reason, I feel I have more control in PHP over React(Working hard on React now).

    So is it possible to pass those attributes to PHP? I have tried to set attributes in register_block_type(), but still I cannot get those attributes in Gutenberg.

    Moderator bcworkz


    The render callback is only passed what it needs to do its job. To pass other attributes you’d need to define your own block. Clearly that would not help all of the existing blocks you already have used. What is it you are actually trying to accomplish? Maybe there’s another way to do it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get all attributes of a block in PHP?’ is closed to new replies.