• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How To Override WordPress Gutenberg Core Blocks Output

Wordpress · April 19, 2022

WordPress ships with a bunch of neat core Gutenberg blocks. However, there may be situations where you need to change the output of a Gutenberg block. In my use case, I needed to modify the core/image block to add an image credit field I created using Advanced Custom Fields.

Like most things in WordPress, this is possible using an action and a few lines of code. Some solutions around on the internet make you call register_block_type to override the registration of the core block (which is wrong, in my opinion).

The register_block_type_args filter is called from within class-wp-block-type.php, which allows you to override the render_callback property.

add_filter( 'register_block_type_args', 'core_image_block_type_args', 10, 3 );
function core_image_block_type_args( $args, $name ) {
    if ( $name == 'core/image' ) {
        $args['render_callback'] = 'modify_core_image';
    }
    return $args;
}

function modify_core_image($attributes, $content) {
  	// Modify core image return content or something new here
	return $content;
}

Simply replace the name if statement value with the block you want to check for.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • Thoughts on the Flipper Zero
  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • How to Use Neural DSP Archetype Plugins With the Quad Cortex
  • Smoke Detector Randomly Goes Off Early Hours of The Morning
  • NBN Box Installed Inside of Garage, Where Do You Put The Modem?
  • How To Mock uuid In Jest
  • Removing A Character From The Start/End of a String In Javascript
  • How to Copy Files Using the Copy Webpack Plugin (without copying the entire folder structure)

Recent Comments

  • kevmeister68 on I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • BBosman on Unpkgd Is Down (Again)
  • Odie on Neural DSP Reveal Details About the Long-Awaited Quad Cortex Desktop Editor
  • David Baumann on Neural DSP Reveal Details About the Long-Awaited Quad Cortex Desktop Editor
  • Julius on Is Web 3.0 Just Another Crypto Hype Scam?

Copyright © 2022 · Dwayne Charrington · Log in

wpDiscuz