• 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

  • How To Get The Hash of A File In Node.js
  • Testing Event Listeners In Jest (Without Using A Library)
  • Which Neural DSP Archetype Plugins Should You Buy?
  • NBN Box Installed Inside of Garage, Where Do You Put The Modem?
  • Smoke Detector Randomly Goes Off Early Hours of The Morning
  • How to Use Neural DSP Archetype Plugins With the Quad Cortex
  • Wild Natural Deodorant Review
  • How to Fast Launch Microsoft Flight Simulator 2020 (decrease game loading time)
  • How To Install Eufy Security Cameras Without Drilling or Using Screws
  • Perfectly Smoked Steak On A Charcoal BBQ Using Indirect Heat

Recent Comments

  • Thebe on How to Remove the My Sites Menu From the WordPress Admin Bar
  • Maccas worker jn the 2000s on Dear McDonald’s: bring back the Warm Cookie Sundae, you cowards
  • Anamika Singh on Testing Event Listeners In Jest (Without Using A Library)
  • Stefan on A List of WordPress Gutenberg Core Blocks
  • pandammonium on A List of WordPress Gutenberg Core Blocks

Copyright © 2022 · Dwayne Charrington · Log in

wpDiscuz