I have a widget located at /child-theme/includes/custom-widget.php.

How do I call register_widget and reference that widget?

I've tried something like the following inside functions.php:

function SER_register_widgets() { 
  register_widget( 'includes/custom-widget.php' );
add_action( 'widgets_init', 'SER_register_widgets' );

but this does not work.

Help appreciated.

2 Answers 2


include that file in your functions.php file like


then you can call add_action() hook, in your case

add_action('widgets_init', 'SER_register_widgets'); .

the idea is to make that function ( ser_register_widgets ) visible in current php file ( functions.php file in this case )


OK, that's not how PHP works... ;)

register_widget function gets exactly one param - widget class... You can't pass a file path as a class name... Of course you have to make sure, that such class exists (so you have to include file with that class).

include_once( 'includes/custom-widget.php' );

function SER_register_widgets() { 
  register_widget( 'My_Custom_Widget_Class' );  // <-- change to real class
add_action( 'widgets_init', 'SER_register_widgets' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.