• I am trying to rebuild core/image block to add extra link in the caption, which would be a link to the extended description of object in the image on another page.

    This requires both modifying block edit interface, as well as saved markup. So I opted to take core/image block from github (and necessary dependency in embed folder).

    After little modifying of block (removing unneded exports in index.js of the block and adding registerBlock – because block registering for Gutenberg is done for all core blocks in single js file), block compiles fine. However, in the WordPress Gutenberg editor, block throws an error. Error is:

    Uncaught TypeError: Object(…) is not a function

    I tracked down error to useBlockProps hook, which is undefined in javascript, although it is imported before (import { BlockAlignmentToolbar, BlockControls, BlockIcon, MediaPlaceholder, useBlockProps } from ‘@wordpress/block-editor’;) I am using @wordpress/create-block scaffold and mentioned imports resolve through webpack.

    Why am I getting an error an how to fix it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @lovor. What version of WordPress are you using? Do you have the Gutenberg plugin installed and activated? useBlockProps was only introduced in WordPress 5.6 so it might be that this is why it’s undefined.

    Thread Starter Lovro Hrust

    (@lovor)

    Yes, that was the reason. I took 5.5 version and it was working fine. I was unaware of Block API changes in 5.6.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Rebuilding wordpress core image block’ is closed to new replies.