Skip to content

Snippet: How to Override Custom Widgets

You can override any of the Total theme's custom widgets via your child theme. Simply copy the widget file from the Total Theme Core plugin under total-theme-core/inc/widges/ into your child theme (best to create a widgets folder in the child theme and add them there), remove the widget from loading via the theme using the wpex_cusotm_widgets hook and then include the file hooked into the widgets_init file. See the snippet below.

Important: Most widgets have filters/hooks you can use to modify them without having to override the widget completely. It's highly you do not override the widgets completely. If there is something you are trying to modify and not sure how let us know via the theme comments or open a ticket and we can show you the best way possible to achieve what you want.

// Remove custom widget from loading inside the theme
add_filter( 'wpex_custom_widgets', function( $widgets ) {
   unset( $widgets['posts-thumbnails'] ); // Remove post thumbnails widget @see plugins/total-theme-core/total-theme-core.php for the list of widgets
   return $widgets;
} );

// Load custom widget file from child theme
function myprefix_include_custom_widgets() {
	require_once( get_stylesheet_directory(). '/widgets/posts-thumbnails.php' );
}
add_action( 'widgets_init', 'myprefix_include_custom_widgets' );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top