Move require_once "inc/custom.php"; to bottom of functions.php

Hello, I’ve found that I need to go into block code to make more advanced changes to some blocks that cannot be done via the UI. I’m able to get things started with the UI, then copy all the code to the blocks directory in my PG project. After that, I change the code and the only thing left is to manually register the block, but I can’t do that in inc/custom.php because it’s called before all the blocks are registered.

Can require_once "inc/custom.php"; be called after the blocks in fuctions.php?

-Thanks!

1 Like

@jonroc the best way is to use WP hooks to ensure that the code runs at the correct time. For example, blocks are registered in the init hook with the default priority 10.

If you wish to run some code after all the blocks are registered use this in inc/custom.php:

add_action( 'init',function() {
    //do something
}, 100);

The priority parameter 100 causes this hook to be called at the end.

1 Like