WP Rig custom filters and hooks
WP Rig provides several custom hooks to extend its core functionality without modifying core component files directly. These filters should be used to add or modify theme assets and behavior.
Theme Identity & Namespace
When using filters or creating new PHP components, you MUST reference the config/config.json.
- Namespace: Use
theme.PHPNamespaceinstead of assumingWP_Rig. - Slug: Use
theme.slugfor text domains and unique identifiers.
CSS and JS Assets
wp_rig_css_files
Filters the list of CSS files enqueued by the theme. Use this to add custom stylesheets that are enqueued and potentially preloaded.
Usage Example:
add_filter( 'wp_rig_css_files', function( $css_files ) {
$css_files['my-custom-handle'] = [
'file' => 'my-custom.min.css', // Relative to assets/css/
'global' => false, // Optional: set to true to enqueue globally
'preload_callback' => 'is_single', // Optional: condition for preloading
];
return $css_files;
} );
wp_rig_js_files
Filters the list of JS files enqueued by the theme.
Usage Example:
add_filter( 'wp_rig_js_files', function( $js_files ) {
$js_files['my-custom-handle'] = [
'file' => 'my-custom.min.js', // Relative to assets/js/
'global' => true, // Enqueue on all pages
'loading' => 'async', // Optional: 'async' or 'defer'
'footer' => true, // Load in footer
];
return $js_files;
} );
wp_rig_preloading_styles_enabled
Enables or disables style preloading globally.
Typography and Fonts
wp_rig_google_fonts
Filters the array of Google Fonts to download and use in the theme.
Usage Example:
add_filter( 'wp_rig_google_fonts', function( $fonts ) {
$fonts[] = [
'font-family' => 'Open Sans',
'font-weight' => '400,700',
'font-style' => 'normal,italic',
];
return $fonts;
} );
UI and Navigation
Icon SVGs
wp_rig_dropdown_icon_svg: Filters the SVG for submenu dropdown buttons.wp_rig_menu_toggle_icon_svg: Filters the SVG for the mobile menu toggle button.wp_rig_menu_close_icon_svg: Filters the SVG for the menu close button.
wp_rig_customizer_settings
Filters the theme settings used in the Customizer and available via wp_rig()->get_setting().
Best Practices for Agents
- Prefer hooks over core edits: When adding new styles or scripts, always use the
wp_rig_css_filesandwp_rig_js_filesfilters infunctions.phpor a custom component instead of editinginc/Styles/Component.phporinc/Scripts/Component.phpdirectly. - Follow WP Rig file structure: Place your custom CSS files in
assets/css/src/and JS files inassets/js/src/, and ensure they are processed by the build system (usingnpm run dev). - Leverage preloading: For critical styles that only load on certain pages, use the
preload_callbackinwp_rig_css_filesto improve performance. - Use
wp_rig()->get_setting(): For theme options, use the built-in setting getter instead ofget_theme_mod()directly.